robots.tsx 751 Bytes
Newer Older
mayi's avatar
mayi committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
import React, { useContext } from "react";
import style from "./Robot.module.css";
import { appContext, appSetStateContext } from "../AppState";
import {withAddToCart} from './AddToCart'
export interface Robotprops {
  id: number;
  name: string;
  email: string;
  addToCart:(id,name)=>void
}
const Robot: React.FC<Robotprops> = ({ id, name, email,addToCart }) => {
  const value = useContext(appContext);

  return (
    <>
      <div className={style.cardContainer}>
        <img src={`https://robohash.org/${id}`} alt="root" />
        <h2>{name}</h2>
        <p>{email}</p>
        <p>{value.username}</p>
        <button onClick={()=>addToCart(id,name)}>加入购物车</button>
      </div>
    </>
  );
};
export default withAddToCart(Robot);