Skip to content

Using MobX useLocalObservable with React Component Props #2536

Answered by urugator
codeBelt asked this question in Q&A
Discussion options

You must be logged in to vote

and making sure your state is lifted-up.

Not "and" - the point of lifting state up is to remove the need for syncing.
There is no need to create widget store lazily on component mount and then keeping it in sync with props.
Whether or not some widget component will be rendered depends on state. So the state knows upfront which widget stores are needed.
So you can create the widget store instances inside constructors/actions upfront and pass them to components with ctx/props.
Eg you could have some DashboardPageStore which creates an array of widget stores in constructor and then just pass them to widget components.

Seems like calling the childStore.init method within useEffect is the p…

Replies: 5 comments 11 replies

Comment options

You must be logged in to vote
1 reply
@danielkcz
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
10 replies
@urugator
Comment options

@codeBelt
Comment options

@urugator
Comment options

@codeBelt
Comment options

@urugator
Comment options

Answer selected by codeBelt
Comment options

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