4 ms·
But 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 i
by thomashop 5y ago
But 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).