Infinite loop
f1am3d opened this issue · comments
Why this line called infinitely?
I have same code with other sagas and they are fine.
// api.ts
export getResults({ authParams }: AppRequest): Promise<ApiResponse<ResultsResponseModel>> {
return superagent
.get(withBackend('/results'))
.set(headers(authParams));
}
// sagas/index.ts
export function* rootSaga() {
yield takeEvery(FETCH_RESULTS, fetchResultsSaga)
}
// fetchResultsSaga.ts
export function* fetchResultsSaga() {
const authHeaders = yield select(selectAuthHeaders);
const request: AppRequest = { authParams: authHeaders };
try {
const response = yield call(getResults, request); // CALLED INFINITELY
yield put(fetchResultsSuccessAction(response.body));
}
catch (error) {
console.error(error);
}
}
Greetings!
Could you please share the code used to create fetchResultsSuccessAction
. Could you also share the value of FETCH_RESULTS
. Could you also post how you are dispatching the action for FETCH_RESULTS
?
export function* rootSaga() {
yield takeEvery(FETCH_RESULTS, fetchResultsSaga)
}
Is this actually how you are writing your root saga or is this a simplified version for posting this issue?
The issue was caused because actual string values of two related actions were the same.
Another pitfal of redux. Let's hope that someday it will support integer as action type and we will be able to create unique actions without writing names manually, for example like this:
enum ACTIONS {
SOME_ACTION
}
const action = {
type: ACTIONS.SOME_ACTION
};