multiple instances of a store in React #3186
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It's not about Mobx. JS modules can be stateless and stateful. Stateless modules export functions or classes. Stateful modules export objects. Node.js also supports it: https://gist.github.com/ccnokes/dffe1778059d168ad3cb9c3ee751203a Regarding injecting store in 2021 there are no common rule. You can choose Context API + hooks or singleton modules. Singleton approach won't work in SSR. Node.js process is initialized once and you get shared singleton state between all the HTTP requests which is incorrect. |
Beta Was this translation helpful? Give feedback.
It's not about Mobx. JS modules can be stateless and stateful. Stateless modules export functions or classes. Stateful modules export objects. Node.js also supports it: https://gist.github.com/ccnokes/dffe1778059d168ad3cb9c3ee751203a
On your screenshot you created singleton that's why it works.
Regarding injecting store in 2021 there are no common rule. You can choose Context API + hooks or singleton modules. Singleton approach won't work in SSR. Node.js process is initialized once and you get shared singleton state between all the HTTP requests which is incorrect.