Skip to content

What type do you use to store an object as property that does not belong to a model? #1891

Answered by EmilTholin
andrewdang17 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @andrewdang17!

If the nested models are used just for the User you can inline them if you prefer:

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

const User = types.model({
  id: types.identifier,
  name: types.string,
  pictures: types.model({
    versions: types.model({
      original: types.string,
      thumbnail: types.string
    })
  })
});

const user = User.create({
  id: "1",
  name: "John Doe",
  pictures: {
    versions: {
      original: "http://placekitten.com/800/800",
      thumbnail: "http://placekitten.com/200/200"
    }
  }
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andrewdang17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants