0
React-Native 앱에서 서버에 사용자 이름과 해시를 보내는 구성 요소에 사용자 로그를 작성하고 데이터베이스의 해시와 해시를 비교하여 결과를 반환합니다. 나는 구현 using redux-saga
이 :내 redux-saga가 비동기 인 이유
function* fetchUser(action) {
try {
const user = yield call(Api.fetchUser, action);
yield put({type: types.USER_FETCH_SUCCEEDED, user});
} catch (e) {
yield put({type: types.USER_FETCH_FAILED, message: e.message});
}
}
export function* watchFetchUser() {
yield* takeEvery(types.USER_FETCH_REQUESTED, fetchUser);
}
export default function* rootSaga() {
yield fork(watchFetchUser);
// ...
}
그리고 const user
이 API로부터 응답을 포함하고 yield put({type: types.USER_FETCH_SUCCEEDED, user})
을 후에 실행 것으로 기대. 그러나 yield call(Api.fetchUser, action)
user
이후는 undefined
입니다. 그러나 Api.fetchUser
은 올바른 응답을 반환합니다.
내 실수는 어디에서 발견 할 수 없습니다. 왜 const user = yield call(Api.fetchUser, action)
의 결과가 undefined
일 때 Api.fetchUser
이후에 올바른 응답을 반환합니까?
fetchUser(action) {
const url = `${apiUrls.LOGIN_URL}`;
fetch(url, 'POST', action.user)
.then(response => response.json())
.then(res => res)
}
정말 고마워요! – rel1x