I am using a call back function to update the array inside Dashboard, I confirmed that this is working by using a alert and I also confirmed that the array inside dashboard is updating by using a console.log(cart). But with all this confirmation, the visual cart is not showing the update inside ShopingCart. Now I have to dash out, and this is a major concern since I've been messing around with it for some hours now. Please can someone enlighten me. Should I use useEffect inside ShoppingCart to check? Please Help, must dash!
@Randy_Johnson Ok so cart is set in Dashboard and is passed down through every single layer until it reaches ShoppingCart? IS that correct? Have you considered a context ? https://reactjs.org/docs/context.html
@Sinnbeck Yes its correct, but I am not sure if its the correct way to be doing it. But as the code is now, should the visible update in the shopping cart be happening. Because right now nothing is happening even though cart is being updated when using console log..
@Randy_Johnson I don't see where you're updating the list that's in the dashboard component. You're only updating the list that's created in the PrimaryShoppingCart and when it renders it takes the value again from its props. Therefor nothing will change.
You need to pass the callback that updates the list in the dashboard itself. Or use context as @sinnbeck mentioned.
@Randy_Johnson Its very simple really. Use effect takes 2 parameters.
A callback that will be called if it is "triggered". This can run any code needed. And it can return some sort of cleanup (like removing a timeout or stopping an ajax call)
An array of variables to listen to. An empty array means run once (when the component is loaded). In your case it listens on offer for changes
@Sinnbeck Hey, thanks for your help. This is my first app with ReactJS. Its just the best way for me to really grasp things. I changed the answer because you was right with the context approach for what I need. Makes things much easier.
If anyone finds themselves here. This is a great resource.