MobX allows mutating state, in opposition to Redux.
mobx-react-lite package adds observers, which is a capability of observing
store observables by the components. THose are necessary for apps to work
mobx-react-lite supports only function components and
mobx-react supports class components additionally.
MobX allows to use decorators for indicating oservales, actions, etc. It’s an
experimental feature and it needs to be enabled in
tsconfig.ts, like this:
In the component:
MobX recommends to mutate state only inside actions. If using ASYNC code in
actions state might be mutated outside of action! Solution is to use
runInAction method after any async. Example:
In order to see errors when we mutate state outside of actions, we can do:
in a global context.