CHOI BOO 블로그

[Redux] Redux-Saga 동작 순서

2020.09.17
Redux
redux-saga

components/LoginForm.js

dispatch(loginRequestAction(data));

reducers/users.js

export const loginRequestAction = (data) => { return { type: 'LOG_IN_REQUEST', data, }; };

reducer/users.js

case "LOG_IN_REQUEST": return { ...state, isLoggingIn: true, };

sagas/user.js

function* watchLogIn() { yield takeLatest('LOG_IN_REQUEST', logIn); } export default function* userSaga() { yield all([fork(watchLogIn), fork(watchLogOut)]); }

sagas/user.js

function* logIn(action) { yield put({ type: 'LOG_IN_SUCCESS', data: action.data, }); }

reducers/user.js

case "LOG_IN_SUCCESS": return { ...state, isLoggingIn: false, isLoggedIn: true, me: { ...action.data, nickname: "zerocho" }, };
© CHOI BOO 2021