I am getting this error when i am fetching data from api
export function* fetchAllProductsAsync()
{ const response = yield call(loadAllProductsApi)
yield put({type:types.ALL_PRODUCTS_SUCCESS, payload:response.data})
}
export function* productSaga()
{
yield takeEvery({type:types.ALL_PRODUCTS_REQ, fetchAllProductsAsync})
}
export default productSaga
function* rootSaga(){ yield all([productSaga])}
export default rootSaga
You are mixing together takeEvery
and put
interface.
The put
effect expects just one parameter - the action object with type payload etc. However, the interface of takeEvery
is different, it expects multiple parameters, where the first one is usually the type of the action as a string and the second one is the saga that gets called.
So your takeEvery
call should look like this:
yield takeEvery(types.ALL_PRODUCTS_REQ, fetchAllProductsAsync)
For extra details, check out the docs: https://redux-saga.js.org/docs/api/#takeeverypattern-saga-args