Skip to content

11. redux-saga 로 프로미스 다루기 - await 빠진 부분 추가 #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions redux-middleware/11-redux-saga-with-promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ redux-thunk를 배울 때 사용했던 thunk 함수를 다시 한번 확인해
export const getPosts = () => async dispatch => {
dispatch({ type: GET_POSTS }); // 요청이 시작됨
try {
const posts = postsAPI.getPosts(); // API 호출
const posts = await postsAPI.getPosts(); // API 호출
dispatch({ type: GET_POSTS_SUCCESS, posts }); // 성공
} catch (e) {
dispatch({ type: GET_POSTS_ERROR, error: e }); // 실패
Expand Down Expand Up @@ -397,4 +397,4 @@ export default function posts(state = initialState, action) {

코드가 훨씬 깔끔해졌지요? 매번 API 함수 호출을 위한 사가를 준비 할 때마다 사가 함수를 매번 직접 작성하는 것 보단, 간단한 로직을 가지고 있는 사가 함수의 경우 우리가 만든 유틸 함수로 새로운 사가를 손쉽게 만들어서 쓰면 굉장히 편합니다.

> 지금까지의 코드는 [여기](https://codesandbox.io/s/391ur)서 확인 할 수 있습니다.
> 지금까지의 코드는 [여기](https://codesandbox.io/s/391ur)서 확인 할 수 있습니다.