react-tutorial icon indicating copy to clipboard operation
react-tutorial copied to clipboard

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

Open utterances-bot opened this issue 4 years ago • 2 comments

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

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

utterances-bot avatar Oct 06 '20 04:10 utterances-bot

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

function isPayloadAction<P>(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<typeof asyncActionCreator.request>) { try { const result = isPayloadAction<P1>(action) ? yield call(promiseCreator, action.payload) : yield call(promiseCreator); yield put(asyncActionCreator.success(result)) } catch (e) { yield put(asyncActionCreator.failure(e)) } } } 이런 오류가 뜨는데 도저히 모르겠습니다

syi0808 avatar Oct 06 '20 04:10 syi0808

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

jung-hunsoo avatar Nov 24 '20 12:11 jung-hunsoo