MobX React Bindings

9.2.1 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates creating a MobX observable store and rendering it in a reactive functional React component using the `observer` HOC.

import React from 'react';
import ReactDOM from 'react-dom/client';
import { makeAutoObservable } from 'mobx';
import { observer } from 'mobx-react';

class TimerStore {
  secondsPassed = 0;

  constructor() {
    makeAutoObservable(this);
    setInterval(() => {
      this.secondsPassed++;
    }, 1000);
  }

  reset() {
    this.secondsPassed = 0;
  }
}

const myTimer = new TimerStore();

const TimerDisplay = observer(() => {
  return (
    <div>
      <p>Seconds passed: {myTimer.secondsPassed}</p>
      <button onClick={() => myTimer.reset()}>Reset Timer</button>
    </div>
  );
});

const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(
  <React.StrictMode>
    <TimerDisplay />
  </React.StrictMode>
);

view raw JSON →