Use observables instead of state in React components
Example of maintaining state with a simple observable in your own component:
Note that you are not passing an observable to the "a" component, you are passing a plain value (in this case a Boolean). When the observable changes, the render method above will be re-evaluated by React.
Passing objects with observable properties also makes it easy to control the state of a child component both from within itself and from its parent. A common use case is a popup/overlay component that its parent needs to open and the overlay itself needs to be able to close:
Note that ParentComponent's render method will not be re-evaluated when the active boolean is toggled, only Overlay's.
@action decorator in a React Component will break react-hot-loader
For more on this issue see:
Last updated
Was this helpful?