Skip to main content

Installation

yarn add mobx-keystone

This library requires a more or less modern JavaScript environment to work, namely one with support for:

  • MobX 6, 5, or 4 (with its gotchas)
  • Proxies
  • Symbols
  • WeakMap/WeakSet

In other words, it should work on mostly anything except it won't work in Internet Explorer.

If you are using TypeScript:

  • Version 5.0+ is recommended (standard decorators).
  • Legacy decorators are also supported (experimentalDecorators: true).

Transpiler configuration

This library uses JavaScript decorators and class properties.

Standard decorators

Use this mode if you are on TypeScript 5+ and want standard decorators. For Babel, ensure class static blocks are transformed (for example via @babel/preset-env targets, or by adding @babel/plugin-transform-class-static-block).

tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": false,
"useDefineForClassFields": true
}
}

Legacy decorators

Use this mode if your project is on legacy decorators (experimentalDecorators: true).

tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": true
}
}