PHP & JavaScript engineer/ dog enthusiast. He is working on [PluginMachine](https://pluginmachine.com) a framework for WordPress plugin development.🌱🌵🌲
That example is massively over simplified, I can see why it's confusing. In my case it does need to be decoupled from the component as the state is shared in multiple components. Also, state management is shared with parts of the page that are not created with React.
Yes, what you show works for adding an item. It would still need an updater method.
Would it be possible to lift the state up to the common ancestor of all those components and then drill it down using props? If not, you may want to reach for Redux.
PHP & JavaScript engineer/ dog enthusiast. He is working on [PluginMachine](https://pluginmachine.com) a framework for WordPress plugin development.🌱🌵🌲
What I like about writing state management decoupled from React is I can make that call later. If I have an updateItem, removeItem, and deleteItem, and they have tests, I can choose to use React.useState() or something Redux-like depending on my need.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That example is massively over simplified, I can see why it's confusing. In my case it does need to be decoupled from the component as the state is shared in multiple components. Also, state management is shared with parts of the page that are not created with React.
Yes, what you show works for adding an item. It would still need an updater method.
Would it be possible to lift the state up to the common ancestor of all those components and then drill it down using props? If not, you may want to reach for Redux.
The updater method is
setItems
.Yes. That would be a good startegy.
What I like about writing state management decoupled from React is I can make that call later. If I have an updateItem, removeItem, and deleteItem, and they have tests, I can choose to use React.useState() or something Redux-like depending on my need.