Replies: 2 comments 1 reply
-
You should move the state with data loading etc to a common ancestor. You shouldn't even try to expose a state owned by child to it's parent or to it's siblings. React introduced hooks so that you can easily decouple state/effects from a particular component and make this kind of refactoring trivial. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Take a look at my Next.js/MobX example for ideas https://github.com/codeBelt/mobx-local-global-stores |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a NextJS Page that uses a MobX-driven component –
<AdvancedMobXComponent />
that does data loading etc.This particular Page requires a
<CustomMiniComponent />
that uses some of the data stored inside the MobX state.It seems I could import the StoreProvider and redefine it at the top:
But this leads to StoreProvider inside a StoreProvider (where the inner/original is responsible for the initial state).
Another option I guess is to accept custom Children and pass them like so:
But this might make the layouting too complex as the
<CustomMiniComponent />
is to be displayed in another part of the application and should just access & interact with the state of<AdvancedMobXComponent />
.Are these anti-patterns? Are there better ways to expose the Store to a parent or sibling component?
Beta Was this translation helpful? Give feedback.
All reactions