Search code examples
reactjsmobxmobx-react

What is the correct way to store instance-specific state in MobX


let's assume that I have an application state which I store somewhere as observable. But also I have an instance-specific state. By "instance-specific state" I mean, for example, state of a checkbox - for each instance of checkbox it should be a separate state, like this:

const [isChecked, setIsChecked] = useState(false)

So the question is - What is the correct way to store such instance-specific state in MobX?

And also - should I at all use MobX to handle such instance-specific state? Or should I use useState instead?


Solution

  • It is totally fine to store some state locally inside component!

    For example, if you have a form with different inputs and checkboxes you can just store all of that data inside component and only update some MobX state after form submit.