DEV Community

loading...

Discussion on: Using MobX with React Hooks

Collapse
englund0110 profile image
Søren Englund • Edited

I actually also have a question. How would you be able to call a store, from anywhere else than a hook? Lets say that i have a http class that has a post method that makes a request, and then receives a error back. From my http class i want to call my ToasterStore with that error message, and then the ToasterComponent should update. Is that even possible to do?

Collapse
ryands17 profile image
Ryan Dsouza Author

I think a better option would be that instead of calling the ToasterStore from your http class, you should call your ToasterStore from the store that you are calling your http class method in. Let's call that the DataStore

In MobX, you can combine the DataStore with your ToasterStore by creating a RootStore as described in this article

After that, call you error message method from the ToasterStore in your DataStore, this will maintain separation of concerns as the http class only now has to worry about fetching data and not update the UI.