Skip to content

multiple instances of a store in React #3186

Answered by kubk
noname-username asked this question in Q&A
Discussion options

You must be logged in to vote

I don't understand how this doesn't initialize multiple instances of the same store

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.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@noname-username
Comment options

@urugator
Comment options

Answer selected by noname-username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants