Working with MobX#
Lens uses MobX on top of React's state management system.
The result is a more declarative state management style, rather than React's native
You can review how React handles state management here.
The following is a quick overview:
React.Componentis generic with respect to both
state(which default to the empty object type).
propsshould be considered read-only from the point of view of the component, and it is the mechanism for passing in arguments to a component.
stateis a component's internal state, and can be read by accessing the super-class field
statemust be updated using the
setStateparent method which merges the new data with the old state.
- React does some optimizations around re-rendering components after quick successions of
How MobX Works:#
MobX is a package that provides an abstraction over React's state management system. The three main concepts are:
observableis a marker for data stored in the component's
actionis a function that modifies any
computedis a marker for data that is derived from
observabledata, but that is not actually stored. Think of this as computing
isEmptyrather than an observable field called
Further reading is available on the MobX website.