Skip to content

DevTools ​

Work in Progress

mobx-view-model-devtools is currently a WIP project. The API and features may change at any time.

A standalone devtools panel for inspecting and debugging your ViewModel instances in real time.

Open the floating ViewModels button on this site (or press Ctrl+F12) to try a live demo with 13 real ViewModels. Inspect parent/child models, edit the counter and try property-path search.

Connected ViewModels ​

The inspector shows real parent/child ViewModels, observable state, computed values and methods.

DevTools inspecting the documentation ViewModel hierarchy in the compact glass panel

Search and change history ​

Find a model by its ID or property path, edit values and watch their changes.

DevTools searching the counter ViewModel and showing the watch history for its count

Source: mobx-view-model/packages/devtools


Core compatibility ​

The standalone script auto-discovers stores from the tested core versions 8.10.1, 9.3.16, 10.2.2 and 11.x, in either script load order. It also supports an isolated MobX runtime in the application.

For early 8.0.0, which has no global store-creation hook, explicitly call ViewModelDevtools.connect(viewModelStore) as shown in Option 3. Both the oldest and latest core 8 releases are covered by browser and TypeScript compatibility checks.

Installation ​

The easiest way to inject the devtools is via a <script> tag — no npm install required.

html
<script
  async
  crossorigin="anonymous"
  src="https://unpkg.com/mobx-view-model-devtools/auto.global.js"
></script>

Option 2 — dynamic fetch ​

Use this approach when you need finer control over when the script is loaded (e.g. only in development mode):

html
<script>
  fetch('https://unpkg.com/mobx-view-model-devtools/auto.global.js').then(async response => {
    const script = await response.text();
    const scriptElement = document.createElement('script');
    scriptElement.innerHTML = script;
    document.head.appendChild(scriptElement);
  });
</script>

Option 3 — package dependency ​

Install the devtools package with your package manager:

bash
npm install mobx-view-model-devtools
bash
pnpm add mobx-view-model-devtools
bash
yarn add mobx-view-model-devtools

Then import and connect it directly from your application code:

ts
import { ViewModelDevtools } from 'mobx-view-model-devtools';

ViewModelDevtools.connect(viewModelStore);

To keep the devtools out of production bundles, load the package only in development:

ts
if (process.env.NODE_ENV === 'development') {
  import('mobx-view-model-devtools').then(({ ViewModelDevtools }) => {
    ViewModelDevtools.connect(viewModelStore);
  });
}

Option 4 — Vite plugin ​

If you're using Vite, the mobx-view-model-vite-plugin can connect the devtools automatically — no manual setup required:

ts
import { mobxVmVitePlugin } from "mobx-view-model-vite-plugin";

export default {
  plugins: [mobxVmVitePlugin({ devtools: true })],
};

Connecting to a ViewModelStore ​

The automatic script and the Vite plugin subscribe to store creation and connect stores for you. The automatic script also connects the most recently created store if it loads after that store. Call connect() only when you import the package directly:

ts
ViewModelDevtools.connect(viewModelStore);

Example ​

ts
import { ViewModelStoreBase } from 'mobx-view-model';

const viewModelStore = new ViewModelStoreBase();

ViewModelDevtools.connect(viewModelStore);

Connecting extra data ​

You can also expose arbitrary data (e.g. global stores, services) alongside your ViewModels:

ts
ViewModelDevtools.connectExtras({ foo: 'bar' });

This is useful for attaching a RootStore or any other object you want to inspect in the panel.


Development-only setup ​

To avoid loading devtools in production, wrap the injection in a condition:

ts
if (import.meta.env.DEV) {
  const script = document.createElement('script');
  script.src = 'https://unpkg.com/mobx-view-model-devtools/auto.global.js';
  script.crossOrigin = 'anonymous';
  script.async = true;
  document.head.appendChild(script);
}