1、普通商品卡片
2、打折商品卡片
3、拥有复用的页面逻辑:加入购物车 addToCart
分别从高阶函数和自定义hook方向改造
const addToCart: AddToCartFn = (id, name) => {
if (setState) {
setState((state: any) => {
return {
...state,
shoppingCart: {
items: [...state.shoppingCart.items, { id, name }]
}
}
})
}
}
命名规范:withXxxx
命名规范:useXxxx
方法:useAddToCart