Go ProSign in

Create Relationships in your Data with mobx-state-tree Using References and Identifiers

MST stores all data in a tree, where each piece of data lives at one unique location. In most state management solutions, this means you need to introduce weakly typed, primitive 'foreign keys' to refer to other parts of the state tree. But in MST you can leverage the concepts of references and identifiers to relate model instances to each other. MST will do the normalization behind the scenes for you.

In this lesson you will learn:

  • The use of types.identifier to uniquely identify an instance of a specific type
  • The use of types.reference to refer to data in another part of the tree, and with which you can interact with in another part of the tree
  • The use of types.maybe to make as ".. or null" type
  • Using types.late to create circular type definitions

You must be a Member to view code