i have a child component where i click on the product to add to the cart, but the cart is located in the parent component, i tried to use localStorage to somehow pass the data from the child to the parent component. i can see the data in the localStorage but i can't get it in the parent component, i know my approach is a bit off, I would like some feedback on how to get it to work. i see a lot of people using Redux, but am not familiar with it.
#problem with managing add to cart with localStorage
3 messages · Page 1 of 1 (latest)
There are several ways to handle this including several state management packages (Redux, React Query). You could do this "out of the box" using the Context API (if you've gotten that far with your learning) or in this case you can simply provide an "onProductAdded" callback to your component...
That would look somthing like the parent defining an "onProductAdded(productToAdd)" function and then passing that to the child as a parameter. Then in the child can simply call that function when a product needs to be added.
Thank you for the reply, i found another way using an <Outlet />, it turns out there is a way to pass data easily through <Outlet /> after almost 4 days of working on it, it finally worked.