Trees, types and state

Each node in the tree is described by two things:

  1. Type: the shape of the thing
  2. Data: the state it is currently in

The simplest tree possible:

import {types} from "mobx-state-tree"

// declaring the shape of a node with the type `Todo`
const Todo = types.model({
    title: types.string
})

// creating a tree based on the "Todo" type, with initial data:
const coffeeTodo = Todo.create({
    title: "Get coffee"
})

The types.model type declaration is used to describe the shape of an object. Other built-in types include arrays, maps, primitives, etc. The type information will be used for both.

results matching ""

    No results matching ""