mobx-react-lite
Lightweight React bindings for MobX based on React 16.8+ and Hooks
Last updated 2 years ago by mweststrate .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install mobx-react-lite 
SYNC missed versions from official npm registry.

mobx-react-lite

CircleCI Coverage Status NPM downloadsMinzipped size Discuss on Github View changelog

This package supports React function components only. Use mobx-react if you also need class component support. It is still possible to use <Observer> inside the render of class components.

Compatibility table (major versions)

mobx mobx-react-lite Browser
7 5 Modern browsers with native Proxy support
6 3 Modern browsers (IE 11+ in compatibility mode)
5 2 Modern browsers
4 2 IE 11+, RN w/o Proxy support

mobx-react-lite version 5 requires React 18 or higher.

User Guide 👉 https://mobx.js.org/react-integration.html


API reference âš’

observer<P>(baseComponent: FunctionComponent<P>): FunctionComponent<P>

The observer converts a component into a reactive component, which tracks which observables are used automatically and re-renders the component when one of these values changes. Can only be used for function components. For class component support see the mobx-react package.

<Observer>{renderFn}</Observer>

Is a React component, which applies observer to an anonymous region in your component. <Observer> can be used both inside class and function components.

useLocalObservable<T>(initializer: () => T, annotations?: AnnotationsMap<T>): T

Creates an observable object with the given properties, methods and computed values.

Note that computed values cannot directly depend on non-observable values, but only on observable values, so it might be needed to sync properties into the observable using useEffect.

useLocalObservable is a short-hand for:

const [state] = useState(() => observable(initializer(), annotations, { autoBind: true }))

enableStaticRendering(enable: true)

Call enableStaticRendering(true) when running in an SSR environment, in which observer wrapped components should never re-render, but cleanup after the first rendering automatically. Use isUsingStaticRendering() to inspect the current setting.


Removed APIs in version 5

useObserver, useLocalStore, useAsObservableSource, useStaticRendering, batching imports, observerBatching, and isObserverBatched have been removed. Use observer, <Observer>, useLocalObservable, and enableStaticRendering; React 18 renderers handle batching.

Testing

Running the full test suite now requires node 14+ But the library itself does not have this limitation

In order to avoid memory leaks due to aborted renders from React fiber handling or React StrictMode, on environments that does not support FinalizationRegistry, this library needs to run timers to tidy up the remains of the aborted renders.

This can cause issues with test frameworks such as Jest which require that timers be cleaned up before the tests can exit.

clearTimers()

Call clearTimers() in the afterEach of your tests to ensure that mobx-react-lite cleans up immediately and allows tests to exit.

Current Tags

  • 4.0.7-alpha                                ...           alpha (2 years ago)
  • 3.0.0-beta.1                                ...           beta (6 years ago)
  • 4.0.4-x1                                ...           experimental (3 years ago)
  • 5.1.2                                ...           latest (a month ago)
  • 2.0.0-alpha.5                                ...           next (7 years ago)

87 Versions

  • 5.1.2                                ...           a month ago
  • 5.1.1                                ...           a month ago
  • 5.1.0                                ...           2 months ago
  • 5.0.3                                ...           3 months ago
  • 5.0.2                                ...           3 months ago
  • 5.0.1                                ...           3 months ago
  • 5.0.0                                ...           4 months ago
  • 4.1.1                                ...           a year ago
  • 4.1.0                                ...           2 years ago
  • 4.0.7-alpha                                ...           2 years ago
  • 4.0.7                                ...           3 years ago
  • 4.0.6                                ...           3 years ago
  • 4.0.5                                ...           3 years ago
  • 4.0.4-x1                                ...           3 years ago
  • 4.0.4                                ...           3 years ago
  • 4.0.3                                ...           3 years ago
  • 4.0.2 [deprecated]           ...           4 years ago
  • 4.0.1 [deprecated]           ...           4 years ago
  • 3.4.3                                ...           4 years ago
  • 3.4.2                                ...           4 years ago
  • 3.4.1                                ...           4 years ago
  • 3.4.0                                ...           5 years ago
  • 3.3.0                                ...           5 years ago
  • 3.2.3                                ...           5 years ago
  • 3.2.2                                ...           5 years ago
  • 3.2.1                                ...           5 years ago
  • 3.2.0                                ...           6 years ago
  • 3.1.7                                ...           6 years ago
  • 3.1.6                                ...           6 years ago
  • 3.1.5                                ...           6 years ago
  • 3.1.4                                ...           6 years ago
  • 3.1.3                                ...           6 years ago
  • 3.1.2                                ...           6 years ago
  • 3.1.1                                ...           6 years ago
  • 3.1.0                                ...           6 years ago
  • 3.0.1                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.2.2                                ...           6 years ago
  • 2.2.1                                ...           6 years ago
  • 3.0.0-beta.1                                ...           6 years ago
  • 3.0.0-beta.0                                ...           6 years ago
  • 2.2.0                                ...           6 years ago
  • 2.2.0-beta.0                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.7                                ...           7 years ago
  • 2.0.6                                ...           7 years ago
  • 2.0.5                                ...           7 years ago
  • 2.0.4                                ...           7 years ago
  • 2.0.3                                ...           7 years ago
  • 2.0.2                                ...           7 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 2.0.0-alpha.5                                ...           7 years ago
  • 1.5.2                                ...           7 years ago
  • 1.5.1                                ...           7 years ago
  • 2.0.0-alpha.4                                ...           7 years ago
  • 1.5.0                                ...           7 years ago
  • 2.0.0-alpha.3                                ...           7 years ago
  • 1.4.2                                ...           7 years ago
  • 1.4.1                                ...           7 years ago
  • 2.0.0-test.1                                ...           7 years ago
  • 2.0.0-test.0                                ...           7 years ago
  • 2.0.0-alpha.2                                ...           8 years ago
  • 1.4.0                                ...           8 years ago
  • 1.3.2                                ...           8 years ago
  • 1.3.1                                ...           8 years ago
  • 1.3.1-0                                ...           8 years ago
  • 2.0.0-alpha.1                                ...           8 years ago
  • 1.3.0                                ...           8 years ago
  • 2.0.0-alpha.0                                ...           8 years ago
  • 1.2.0                                ...           8 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.1                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
  • 0.3.7                                ...           8 years ago
  • 0.3.6                                ...           8 years ago
  • 0.3.5                                ...           8 years ago
  • 0.3.4                                ...           8 years ago
  • 0.3.3 [deprecated]           ...           8 years ago
  • 0.3.2                                ...           8 years ago
  • 0.3.1                                ...           8 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.2                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (2)
Downloads
Total 283
Today 0
This Week 0
This Month 199
Last Day 0
Last Week 107
Last Month 2
Dependencies (1)
Dev Dependencies (2)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE