[英]Redux-Saga call not working
我正在嘗試使用redux-saga的call
函數,但未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
。 誰能告訴我我做錯了嗎?
您錯過了一個yield
。 它應該是:
yield call([ NavigatorService, NavigatorService.navigate ], 'Tabs');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.