Access store outside components #2671
-
I want to use axios interceptors to handle request, so I need to find a way to access store without using hooks (because it's forbidden outside components). |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
There is nothing special about accessing mobx stores outside React, as MobX isn't relying on React to work. For more help please describe why you can't/ wouldn't be able to access the mobx store? |
Beta Was this translation helpful? Give feedback.
-
If you are calling axios from react, just grab the store in the component,
and access it through the closure. Otherwise you could import the store
directly. For more help please do include some example code.
…On Mon, Dec 7, 2020 at 9:40 AM HungDang2911 ***@***.***> wrote:
There is nothing special about accessing mobx stores outside React, as
MobX isn't relying on React to work. For more help please describe why you
can't/ wouldn't be able to access the mobx store?
Thanks for your reply.
Inside React Native components, I can use useStores() to access store but
doing the same way in axios interceptor callback function will cause error
(like cannot using hooks outside components).
Currently I'm using MST.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2671 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN4NBFLCSC4LFQOGSI5R33STSPH5ANCNFSM4UQEX7EQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Here is my code //UserStore.ts
|
Beta Was this translation helpful? Give feedback.
Here is my code
//UserStore.ts