Search code examples
mobx-state-tree

Single Object in Mbox State tree?


If I made a store(RegistrationStore) and there is only 1 company created what type do I use?

  .model("RegistrationStore", {
    company: types.optional(????)
  })

Solution

  • It depends of your requirements. E.g. if you should store some properties for companies (name, address, ...) then it is better to create separate Company model.

    In that case you may have following variant (creates new empty company by default):

    .model("RegistrationStore", {
      company: types.optional(Company, Company.create())
    })
    

    or this variant (null value by default):

    .model("RegistrationStore", {
      company: types.maybe(Company)
    })