【问题标题】:Redux-Saga call not workingRedux-Saga 调用不起作用
【发布时间】:2018-01-13 03:43:35
【问题描述】:

我正在尝试使用 redux-saga 的 call 调用一个函数,但该函数没有被调用:

下面是我的saga.js:

import { takeLatest, put, call } from 'redux-saga/effects';
import {NavigationActions} from 'react-navigation';
import NavigatorService from '../services/navigator';
import { SIGN_UP, AUTHENTICATION_FAILED, SIGN_UP_SUCCESS, LOGIN, LOGIN_SUCCESS} from '../actions/index';
import firebase from 'firebase';


function* signUp(action){
    try{
        const auth = firebase.auth();
        const result = yield call([
                      auth, auth.createUserWithEmailAndPassword],
                      action.user.email,
                      action.user.password
                      );
        console.log("signup success") // this is being logged
        call([
            NavigatorService, NavigatorService.navigate],
            'Tabs'
       ); // not being called
      yield put({type: SIGN_UP_SUCCESS, user: action.user});
      console.log("done") // not being logged


    }
    catch(error){
        const error_message = {code: error.code, message: error.message};
        console.log(error_message);
        yield put({type: AUTHENTICATION_FAILED, error: error_message});
    }
}


function* rootSaga(){
  yield takeLatest(SIGN_UP, signUp);
}

export  default rootSaga;

我尝试从其他组件调用NavigatorService.navigate,它工作正常。我什至登录NavigatorService 在这种情况下它没有被记录。谁能告诉我我做错了什么?

【问题讨论】:

    标签: javascript react-native react-redux redux-saga


    【解决方案1】:

    您缺少yield。应该是:

    yield call([ NavigatorService, NavigatorService.navigate ], 'Tabs');
    

    【讨论】:

      猜你喜欢
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 2018-09-03
      • 1970-01-01
      相关资源
      最近更新 更多