Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobx-state-tree: how to rename AnonymousModel to the store name

i am using mobx-state-tree and i would like to actually show the store name when an error appears instead of AnonymousModel.

For example:

const SignupModel = types
  .model({
    isUsingFacebook: false,
    birthday: '',
    timeOfBirth: types.maybeNull(types.string),
    placeOfBirth: types.maybeNull(types.string),
    gender: types.maybeNull(types.string),
    password: '',
  })

Still gives me an error like

Error while converting {...} to AnonymousModel.

But i would like to get

Error while converting {...} to SignupModel.
like image 711
Patrick Klitzke Avatar asked Dec 19 '25 03:12

Patrick Klitzke


1 Answers

Simply pass a desired name as a first argument to model method, like so:

const SignupModel = types
  .model('SignupModel', {
    isUsingFacebook: false,
    birthday: '',
    timeOfBirth: types.maybeNull(types.string),
    placeOfBirth: types.maybeNull(types.string),
    gender: types.maybeNull(types.string),
    password: '',
  })
like image 192
jayarjo Avatar answered Dec 21 '25 19:12

jayarjo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!