Why API is getting called twice in redux-saga?
See original GitHub issueSo, I am trying to dispatch an action to get a request. But I can see that the API is getting called twice but the action dispatched once. Please Help in this -
I did console.log() in both function forgetPasswordSaga and onForgetPasswordButtonClick Result : forgetPasswordSaga is called twice and onForgetPasswordButtonClick called once Component
const Login = (props: Props) => {
const { dispatch } = props;
const onForgetPasswordButtonClick = (data: ForgetPasswordData) => {
dispatch({
type: 'LOGINPAGE_FORGET_PASSWORD_REQUEST',
payload: { data },
});
};
const mapStateToProps = (state: any) => {
const { loading } = state.ui;
return {
loading
};
};
export default connect(mapStateToProps, null)(Login);
Saga
const forgetPasswordSaga = function* (action: Action) {
try {
const response = yield call(forgetPassword, action.payload);
yield put({ type: FORGET_PASSWORD_SUCCESS });
Router.go(RoutePath.LOGIN);
return response;
} catch (e) {
yield put({ type: FORGET_PASSWORD_FAIL });
yield put({ type: ERROR_SET, metadata: { message: Error.getErrorMessage(e) } });
}
};
export default [
takeLatest('LOGINPAGE_FORGET_PASSWORD_REQUEST', forgetPasswordSaga),
];
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:22 (6 by maintainers)
Top Results From Across the Web
Why API is getting called twice in redux-saga? - Stack Overflow
So, I am trying to dispatch an action to all a get request. But I can see that the API is getting called...
Read more >How to prevent redux-saga from calling my api call twice?
Coding example for the question How to prevent redux-saga from calling my api call twice?-Reactjs.
Read more >Running Tasks In Parallel | Redux-Saga
wrong, effects will be executed in sequence const users = yield call(fetch, ... Because the 2nd effect will not get executed until the...
Read more >Control when Saga Generators are Called with TakeLatest
[01:09] If there's already an instance of the generator function running when it sees this dispatched type, it will cancel it and start...
Read more >Multiple api calls even for single saga action?
I was facing this issue in my React app and I could not find the exact reason in internet. There were many hacks...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Roeefl There could be many possibilities from which this problem could occur. In my case, I was working with multiple sagas. So there is a function called rootSaga where all the other sagas are mentioned.
I was calling the authSaga twice
thanks alot man same problem i was doing i spent approx 3 hours…