I'm working on a project where the user can create 'things' which I then associate state with.
A simple version of how I am doing this is basically:
function App() {
const [things, setThings] = useState({})
}
Unfortunately things ends up being a fairly large and heavily nested (at least a few layers deep anyways) object.
something like this:
{
things: [
{
field1: 'value1',
field2: {...}
...
},
...
],
otherThings: ...
}
I know it is not ideal to store so much in one hook, especially since different parts of it will be basically being constantly updated.
So my question is basically: Is there some way where I can dynamically add different useState hooks, so that my state management looks more like:
const [thing1, setThing1] = useState({...})
const [thing2, setThing1] = useState({...})
const [otherthing1, setOtherthing1] = useState({...})
With different useState hooks being added or removed based on user actions?