Context Consumer not getting updated store values in react/mobx-react-lite #3456
-
Hey, I'm trying to understand the rules of incorporating mobx+context, so I probably do something terribly wrong, but it's seems pretty inconsistent. Intended outcome: BUT Versions Code sandbox with the "bug" (again, not sure it is): |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hello. First of all - if you export store from a module (by making it a singleton) you don't need context at all. I've fixed your example: https://codesandbox.io/s/mobx-lite-with-react-context-forked-fz64fk The second approach is to avoid singleton (they don't work in SSR) by using React context. Here is another working example: https://codesandbox.io/s/mobx-lite-with-react-context-forked-ohp982 |
Beta Was this translation helpful? Give feedback.
-
Please see https://mobx.js.org/react-integration.html#callback-components-might-require-observer Feel free to add |
Beta Was this translation helpful? Give feedback.
Please see https://mobx.js.org/react-integration.html#callback-components-might-require-observer
Feel free to add
<MyContext.Consumer>
usage as another example to docs.