我想获得我的 items' with a api call inside
useEffect`:
export const MyComponent = () => {
// const cartContext = useCartContext();
let [items, setItems] = useState([]);
useEffect(() => {
api.get('cart?detail=true').then((res: any) => {
const result = res;
setItems(result.gifts);
}).catch(err => {
console.log(err);
})
});
return (
<div className="cart-factor-items">
{
items.map((item, index) => {
return (
<div>....</div>
但我收到此错误消息:
Rendered more hooks than during the previous render.