Skip to content

How can I use React Hook in actions? #1689

Answered by thanksyouall
thanksyouall asked this question in Q&A
Discussion options

You must be logged in to vote

I found a solution. It turns out that you can add axios.interceptors anywhere. And it will work globally.
So just call axios.interceptors in any React component. And now we can use our store in it.

const SomethingComponent = observer(() => {
   const store = useStore()
   
   httpClient.interceptors.response.use(function (response) {
      return response;
   }, (error) => {
      ...
     // For example:
     store.setError(error)
   })

   return (...)
})

export default SomethingComponent

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@thanksyouall
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by thanksyouall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants