Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

What are model .props() and how to use them?#2264

Discussion options

What are model.props() and how to use them?

Can I give labels to fields using them?

You must be logged in to vote

.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

Comment options

.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.

You must be logged in to vote
2 replies
@OnkelTem
Comment options

That makes much sense, thank you!

Currently I usetypes.compose() to add props.
But seems like with.props() I can not only&-new props, but override existing ones, like totally replacing the original prop type. Is that so?

@coolsoftwaretyler
Comment options

Correct

Answer selected bycoolsoftwaretyler
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@OnkelTem@coolsoftwaretyler

[8]ページ先頭

©2009-2025 Movatter.jp