I want to get my 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>
but I got this error message:
Rendered more hooks than during the previous render.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment