how do you read data from a store outside of react? #122
-
Hi, so i've got a basic store set up like
So I find that if I make calls from outside of a react component, I seem to be able to So the question is, how should you interact with a store outside of a react component? Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi Jonathan, If you really need to get a store's state outside of React- the recommended way is to use Also- I wouldn't recommend adding functions directly on their store class like you're doing here. Internally, the class recreates itself at some points (after server rendering and such) and it might lose those properties. Rather just create a separate object called Hope that helps! |
Beta Was this translation helpful? Give feedback.
Hi Jonathan,
If you really need to get a store's state outside of React- the recommended way is to use
Store.getRawState()
- which will return the actual state snapshot of that store at that time. Using hooks outside of React components will give you weird results, like maybe what you're seeing.Also- I wouldn't recommend adding functions directly on their store class like you're doing here. Internally, the class recreates itself at some points (after server rendering and such) and it might lose those properties. Rather just create a separate object called
ImageStoreActions
or something that's external to the store, to hold those functions.Hope that helps!