An opinionated MobX with mobx-state-tree
MobX is very flexible in how you organize your state and apply the various actions and reactions. However, it does leave some questions for you to answer:
- Should classes be used or just plain objects with
extendObservable()
? - How should the data be normalized?
- How to deal with circular references when serializing the state?
- And many more
mobx-state-tree
is a package that gives you prescriptive guidance for organizing and structuring your observable state. Adopting the MST style of thinking gives you several benefits out of the box. In this section, we will explore this package and its benefits.
Models – properties, views, and actions
mobx-state-tree
as the name suggests, organizes the state in a tree of models. It's a model-first approach, where each model defines the state that needs to be captured. Defining the model adds the ability to type-check the model assignments at runtime and guard you against inadvertent changes. Combining the runtime checks with...