0
약속을 지키지 않은 상태에서 약속을 파견해야합니다. 다음 코드 (주석 처리 된)를 시도했지만 성공하지 못했습니다.redux에서 약속을 수행하는 방법은 무엇입니까?
올바른 방향으로 나를 가르쳐 주시겠습니까? 내가 할
오류는 다음과 같습니다
ReferenceError: dispatch is not defined
const getLocations = (query:string):ActionType => {
const value = query.trim()
if (!value.length) {
return ({
type: null,
payload: null
})
}
return ({
type: types.GET_LOCATIONS,
payload: new Promise((resolve, reject) => {
fetch(api.find(query)).then(response => {
resolve(response.json())
// dispatch(myAction())
})
})
})
}
비동기 작업 [here] (http://redux.js.org/docs/advanced/AsyncActions.html)에서 문서 페이지를 확인하고 [redux- 썽크] (https://github.com/gaearon/redux-thunk)와 내가 선호하는 [redux-saga] (https://github.com/redux-saga/redux-saga)를 비동기 데이터 흐름에 사용할 수 있습니다. – cssko