velopert / react-tutorial

벨로퍼트와 함께하는 모던 리액트 튜토리얼 문서
https://react.vlpt.us/
347 stars 98 forks source link

11. redux-saga 로 프로미스 다루기 · GitBook #50

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

11. redux-saga 로 프로미스 다루기 · GitBook

https://react.vlpt.us/redux-middleware/11-redux-saga-with-promise.html

syi0808 commented 3 years ago

안녕하세요 saga 리팩토링 도중 import { call, put } from 'redux-saga/effects' import { AsyncActionCreatorBuilder, PayloadAction } from 'typesafe-actions' type PromiseCreatorFunction<P, T> = ((payload: P) => Promise | (() => Promise))

function isPayloadAction

(action: any): action is PayloadAction<string, P> { return action.payload !== undefined }

export default function createAsyncSaga<T1, P1, T2, P2, T3, P3>( asyncActionCreator: AsyncActionCreatorBuilder<[T1, [P1, undefined]], [T2, [P2, undefined]], [T3, [P3, undefined]]>, promiseCreator: PromiseCreatorFunction<P1, P2> ) { return function* saga(action: ReturnType) { try { const result = isPayloadAction(action) ? yield call(promiseCreator, action.payload) : yield call(promiseCreator); yield put(asyncActionCreator.success(result)) } catch (e) { yield put(asyncActionCreator.failure(e)) } } } 이런 오류가 뜨는데 도저히 모르겠습니다

jung-hunsoo commented 3 years ago

@syi0808 음.. 제 코드에서는 리팩터링 이후에도 에러없이 동일하게 작동하고 있습니다. 아마도 오타나 신텍스를 한 번 체크해보시면 될 것 같습니다.