3 ms·
>Could you give a piece of usable code that highlights the problem A shopping cart. The cart state exists in the header of the web page, but the "add to cart"
by nemothekid 5y ago
>Could you give a piece of usable code that highlights the problem
A shopping cart. The cart state exists in the header of the web page, but the "add to cart" button exists on the product description, far away from the cart. Ultimately, I think, it ends up being a question about state management which is always the hardest part of UI frameworks IMO
- thomashop 5y agoBut a shopping cart is just a piece of state which you modify through an event listener to a button which in turn updates the UI again. These days you can do it with a useState or useReducer hook but there are countless ways to implement it, react or not.
- nemothekid 5y agoBut where does that state live? I imagine GP would like to live on the `Cart` component, but since the Add to Cart button isn't a child of the Cart component, you would have to "pass up" some connector. Alternatively you would just have the state live in a common ancestor of both (or at the Root) but I imagine that GP doesn't like that either (global state).