mobx-react provides the official React bindings for MobX, enabling the creation of fully reactive React components that automatically re-render when the observable data they consume changes. The current stable version is 9.2.1, which includes support for React 19 and MobX 6.x. This package offers a complete integration, including support for class-based components, the legacy `Provider`/`inject` mechanism, and `PropTypes` utilities for observable-based property checkers. It differentiates itself from `mobx-react-lite` by offering these additional features for existing codebases or specific architectural needs, whereas `mobx-react-lite` is optimized for modern functional components and Hooks with `React.createContext`. Releases often align with new React and MobX versions, providing timely compatibility updates and bug fixes.
npm install mobx-reactVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating a MobX observable store and rendering it in a reactive functional React component using the `observer` HOC.
Upgrade `mobx-react` to v6 or higher to support MobX 6.x. Ensure `mobx` is also updated to a compatible version (e.g., `^6.9.0` for `mobx-react@9`).
For new functional components, use `React.createContext` and `React.useContext` instead. For class components, consider refactoring or creating specific context providers.
Migrate to TypeScript for robust static type checking and better developer experience. If not using TypeScript, standard React `PropTypes` are still applicable for non-observable props.
Do not manually wrap functional components in `React.memo` before passing them to `observer`. Apply `observer` directly.
Ensure `mobx-react` is at least version 9.0.0 to guarantee full compatibility and correct behavior in React's strict mode, especially with React 18.2 and React 19.
Ensure `observer` is applied only once to your functional components. Remove any redundant `React.memo` wrappers if present before `observer`.
Use `disposeOnUnmount` for class components or manual cleanup with `useEffect` for functional components to dispose of MobX reactions, autoruns, or other subscriptions when the component unmounts.
Ensure the component is wrapped with `inject` and rendered within a `Provider` that supplies the necessary stores. For new code, consider `React.createContext` and `useContext` instead.