简体   繁体   中英

Redux-Saga call not working

I am trying call a function using redux-saga's call but the function is not being called:

below is my 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;

I have tried calling NavigatorService.navigate from other components and it works fine. I am even logging in NavigatorService in this case it's not being logged. Can anyone please tell what I am doing wrong?

You are missing a yield . It should be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM