-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New Flux store instance created upon second component referencing store #467
Comments
This is hard to debug without seeing the code to understand your issue, or a minimal repro. One thing to make sure you are doing is exporting an instantiated version of a store and not the store's class, like this in the examples: https://github.com/facebook/flux/blob/master/examples/flux-todomvc/src/data/TodoStore.js#L67 |
Yes, that's what I'm doing. It's not behaving like a Singleton. WTStore.js contain: export default new WTStore(); DataView.js (and Login.js) contain: import WTStore from '../stores/WTStore'; |
If you are doing that then I don't have a guess at what else might be wrong without seeing a more complete example. Can you repro the same issues in one of the examples? Or provide more code/minimal repro? |
I'll work on getting a simplified version that reproduces the behavior. Am I correct in that it shouldn't create a new instance of the store? Thank you. |
I believe so, there should typically only be one instance of any given store. They should act like singletons. |
There is one instance at a given time. The problem is the store state is wiped when the second component references the store. |
Without an example of the bug it's going to be hard for me to help you further. I've not heard of this happening before other than at times where someone is accidentally re-instantiating new instances of the store rather than it being used as a singleton. |
I have one Flux store that is imported by two components. One a security based component and the other an app business data view. That Login.js component successfully logs in using Okta, obtains user info. from the application and stores it in the Flux store. The user navigates to the app data page, the dataview.js, which imports the store, uses it to retrieve user info before making fetch calls. The problem is the user state in the store is now undefined since the store has been newly constructed. It seems since the user info has not changed it should not be removed. The app data is still null since it hasn't retrieved the info yet. The store should behave like a singleton and ONLY update state when an action has been dispatched.
The text was updated successfully, but these errors were encountered: