Skip to main content

Get Started

Installation

npm install mobx-accessor mobx

We must also install mobx since mobx-accessor is powered by it.

Quick Start

import {
mutationTree,
makeAccessor,
} from 'mobx-accessor';

const defState = () => ({
value: 1,
});

const defMutations = mutationTree({ state: defState }, {
increase(state) {
state.value++;
},
});

const accessor = makeAccessor({
state: defState,
mutations: defMutations,
});

console.log(accessor.value); // -> 1
accessor.increase();
console.log(accessor.value); // -> 2

Level Up

See Usage for how to build an full-featured accessor.