import React, { useContext } from "react"; import style from "./Robot.module.css"; import { appContext, appSetStateContext } from "../AppState"; import {useAddToCart} from './AddToCart' interface Robotprops { id: number; name: string; email: string; } const RobotDiscount: React.FC<Robotprops> = ({ id, name, email }) => { const value = useContext(appContext); const addToCart =useAddToCart(); return ( <> <div className={style.cardContainer}> <img src={`https://robohash.org/${id}`} alt="root" /> <h2>打折商品</h2> <h2>{name}</h2> <p>{email}</p> <p>{value.username}</p> <button onClick={()=>addToCart(id,name)}>加入购物车</button> </div> </> ); }; export default RobotDiscount ;