- Notifications
You must be signed in to change notification settings - Fork638
What are model .props() and how to use them?#2264
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
What are model Can I give labels to fields using them? |
BetaWas this translation helpful?Give feedback.
All reactions
.props() is just another builder method on model types that allows you to add or override props given to a model.See docs.
constSomeModel=types.model({firstName:"Tyler"}).props({lastName:"Williams"})constmodelInstance=SomeModel.create()console.log(modelInstance.firstName)// Tylerconsole.log(modelInstance.lastName)// Williams
More useful if you're extending an existing model, in my opinion. But some people useprops instead of the initial properties argument to thetypes.model function.
Replies: 1 comment 2 replies
-
constSomeModel=types.model({firstName:"Tyler"}).props({lastName:"Williams"})constmodelInstance=SomeModel.create()console.log(modelInstance.firstName)// Tylerconsole.log(modelInstance.lastName)// Williams More useful if you're extending an existing model, in my opinion. But some people use |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
That makes much sense, thank you! Currently I use |
BetaWas this translation helpful?Give feedback.
All reactions
-
Correct |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1