Reputation: 21784
In my project we are currently running application wide sagas in store component specific sagas in each component, like this:
public componentDidMount() {
sagaMiddleware.run(componentSpecificSagas);
}
But this means that components using sagas will always have application logic in them, even if they could otherwise be reusable ui components.
What is best practice for running component specific sagas? Should they perhaps just be run in store? Should they perhaps be run in the connector?
Upvotes: 1
Views: 200
Reputation: 5016
Make a root-level saga composed of your application-logic sagas:
function* rootSaga() {
yield spawn(saga1)
yield spawn(saga2)
// ...
}
The run the saga at the root component. Official redux-saga example:
store.runSaga(rootSaga)
render(
<Root
//...
/>,
//...
)
Then the rest of the component tree has no saga logic.
Upvotes: 1