小编Bru*_*osa的帖子

Sagas和取得承诺

由于这个API请求,我在这里最后几分钟一直在桌子上敲我的头......

我有以下代码:

佐贺:

export function * registerFlow () {
  while (true) {
    const request = yield take(authTypes.SIGNUP_REQUEST)
    console.log('authSaga request', request)
    let response = yield call(authApi.register, request.payload)
    console.log('authSaga response', response)
    if (response.error) {
      return yield put({ type: authTypes.SIGNUP_FAILURE, response })
    }

    yield put({ type: authTypes.SIGNUP_SUCCESS, response })
  }
}
Run Code Online (Sandbox Code Playgroud)

API请求:

// Inject fetch polyfill if fetch is unsuported
if (!window.fetch) { const fetch = require('whatwg-fetch') }

const authApi = {
  register (userData) {
    fetch(`http://localhost/api/auth/local/register`, {
      method  : 'POST',
      headers : { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux redux-saga react-redux

3
推荐指数
1
解决办法
3671
查看次数

标签 统计

javascript ×1

react-redux ×1

reactjs ×1

redux ×1

redux-saga ×1