Let's say I have a saga that looks so:
export function* incrementAsync(action) {
try {
const res = yield call(Api.signin.create, action.payload);
yield put({
type: USER_SIGN_IN_FETCH_SUCCESS,
payload: res.data.auth
};
} catch (e) {
yield put({ type: USER_SIGN_IN_FETCH_ERROR_NETWORK });
}
}
The fech was a success, but that doesn't mean that the user was actually logged in:
res.data.auth.error
could be true
My question is whether I should do things like:
if (//user was succesfully logged in)
yield put(//user was successfully logged in)
else if //wrong username
yield put(//wrong username)
else if //wrong password
yield put(//wrong password)
Or should I have only one for success and one for error, and in the reducer analyze the logic and build the store relative to the response data?
USER_SIGN_IN_FETCH_SUCCESS
only makes sense if there's some kind of loading animation going on, since it's not necessarily a login success. The saga should yield meaningful actions, so your whole logic is clearer, and easier to debug through the Redux dev tools. – GaseousSTARTED
,SUCCEEDED
,FAILED
, etc.) and the rest of the logic goes into my API integration code (mostly vanilla JS wrapping API calls returning promises). – Gaseousselector
for data analyze – Conglobate