Reputation: 34818
When using redux-saga with react-native what is the best practice in terms of when you run/stop sagas? That is should the approach be:
a) run all sagas straight in one hit when starting the app from early in the app cycle (like I see in the short redux-saga examples), or
b) start specific sagas in the "componentDidMount" for a specific "screen/page" within that component (e.g. showListContainer.js)
Also if the saga is say waiting for myList updates from external sources (firebase's firestore in this case) then this would affect the choice above then no? That is for option a) above what happens as updates come in here? Or is the concept that the saga would take updates and update the redux store contents, hence in terms of the specific page displaying the updates that would be separate/decoupled? So I guess:
Question 2: Is the concept of react-native use of redux-saga to have the "saga to redux store" work together, and then decouple the react-native visual updates "redux store to react-native updates"
Upvotes: 0
Views: 262
Reputation: 677
You run the saga right at the startup because you want to make sure all the desired side-affects are handled.
Redux-sagas is a side-effect library for redux, so yes. Any saga mutation won't go straight to your react-native views. They have to be first processed by a reducer function which mutates the redux store. Only after that point your smart/connected components should pick up the state changes and update the UI (React-Native level) accordingly.
Upvotes: 1