Tile Sagas for the New Route

In sample sagas, react-boilerplatesagas are exported as an array:

export function* defaultSaga() {

}

export default [
  defaultSaga,
];

The default value is then entered in routes.js:

...
injectSagas(sagas.default);
...

However, when I added a new route for authentication, I get an error message , even if I have only the default sagas (the same as above). saga argument must be a Generator function!

I added a route to routes.js:

//routes.js
export function authRoutes(store) {
  //same code as createRoutes
}

And imported a function to create a new route for Routerin app.js:

//app.js
const rootRoute = {
  component: App,
  childRoutes: createRoutes(store),
};

const authRoute = {
  path: '/auth',
  component: Auth,
  childRoutes: authRoutes(store),
};

const routes = {
  childRoutes: [rootRoute, authRoute],
};

When I try to change the default value to sagas.js:

export default function* root() {
  yield [
    defaultSaga(),
  ];
}

I get an error message . So what I did to wrap in a new route in an array: injectAsyncSagas: Expected "sagas" to be an array of generator functionssagas.default

//routes.js - authRoutes(store)
importModules.then(([reducer, sagas, component]) => {
  injectReducer('login', reducer.default);
  injectSagas([sagas.default]);
  renderRoute(component);
});

Why am I getting these errors and how to fix them? (I am completely new to React and Generators.)

+4
1

. , store.runSaga(mySagas) store.js, , . , .

+1

Source: https://habr.com/ru/post/1676983/


All Articles