So, I'm trying to use reduxtoolkit and want to create addtocart function and when try to set the payload I can't access the object property of my data.
const {data:foods,isPending,error} = useFetch('http://localhost:8000/foods')
const [data, setData] = useState(foods)
useEffect(()=>{
setData(foods)
},[foods]) console.log(data)
console.log(data.name)
const dispatch = useDispatch();
const addToCart = () => {
dispatch(
cartActions.addToCart({
name :data.name,
id:data.id,
price:data.price,
})
)
}
The Error: when I'm trying to log the object property it's returning undefined but when I log the data it showing up