I was using redux-saga
in my application. And use saga
to set the state of my redux
.
But one thing i am experiencing now is the application will hang if I use saga to update the redux state
with a different value from its existing state
Lets say, in my redux
there is state name locale
. first i set it to en
, and create an action CHANGE_LOCALE
to change the locale
state to zh
later.
reducer.js
const initialState = fromJS({
locale: 'en' <- set initial state to en
});
function languageProviderReducer(state = initialState, action) {
switch (action.type) {
case CHANGE_LOCALE:
return state
.set('locale', action.locale);
default:
return state;
}
}
saga.js
export function* loadProfile() {
const profileURL = 'profile';
const profile = yield axios.get(profileURL)
// .then((res) => (res.data))
.then((data) => (data.data));
yield put({
type: ACTION1,
payload: profile,
});
console.log('finish action one');
yield put({
type: CHANGE_LOCALE,
locale: 'zh', <- change to zh using saga
});
console.log('finish action two');
yield put({
type: ACTION3,
payload: profile,
});
console.log('finish action three');
}
export default function* defaultSaga() {
yield takeLatest(constants.LOAD_PROFILE, loadProfile);
}
So when I run the app, the console.log
is just showing finish action one
. Meaning it is hanging after changing the locale
state of Redux
.
( I use Redux Dev Tool to check and it actually has changed the locale
state to'zh'
, -> it actually finish the action two
however , it seems like the saga
dont know what to do next )
p/s: The programm will run sucessfully after hanging for 2 or 3 minutes , so its like saga is stuck and then keep retry after a few minutes and succeed Any help please ??