Search code examples
reduxreact-reduxredux-saga

Redux. How to run several sagas in sagaMiddleWare.run([ f1*(), f2*(), f3*() ]) with redux-saga?


I need the solution to start several sagas in different time points. I had created 3 different saga's and tryed to implement they to the sagaMiddleWare.run() like an array. But for now I gets an error - runSaga(storeInterface, saga, ...args): saga argument must be a Generator function!.

I understand why this error happens, but does not understand how to solve it?

Thank you!

sagaMiddleWare.run([watchSearchForCash, watchBootlegging, watchGraffiti])

Solution

  • You can make it work easly by combining all sagas in one wrapped, called (for example) rootSaga:

    function * rootSaga() {
      yield [
        watchSearchForCash, 
        watchBootlegging, 
        watchGraffiti
      ]
    }
    

    and then implement your new saga holder rootSaga inside the sagaMiddleWare.run(rootSaga)

    Thant's all the magic :)