mobx-preact
This is a fork of mobx-react for Preact
This package provides the bindings for MobX.
Exports the connect
(or observer
) decorator and some development utilities.
Installation
npm install mobx-preact --save
Dependencies
npm install mobx --save
API documentation
connect(stores)(componentClass)
Function (and decorator) that converts a component into a reactive component.
stores
is an array of strings/names of stores you passed to Provider
.
These will be passed automatically to all components connected.
The more components you connect, the better Mobx can optimize rendering. So connect as many components as you want!
See the mobx documentation for more details.
;;; const timeStore = { return <Provider time=timeStore> <TestComponent/> </Provider> ; } @ { const time = thisprops; ; } { return <p>Unix timestamp: timetext</p>; } ;
// If we don't need the stores but still want the component// reactive, then we can omit the stores array @connect //....
Alternatively if you prefer not to use decorators:
//... 'time'App;
You cannot use decorators on stateless components, so wrap them like this:
// With store injectionconst TodoView = { return <p>Current time: propstimetext</p>} // Without injection but still reactiveconst TodoView =
It is possible to set a custom shouldComponentUpdate
, but in general this should be avoided as MobX will by default provide a highly optimized shouldComponentUpdate
implementation based on PureRenderMixin
.
For Mobx documentation, see the mobx project.