gpt4 book ai didi

javascript - Redux-Saga 调用不工作

转载 作者:行者123 更新时间:2023-11-30 14:50:20 25 4
gpt4 key购买 nike

我正在尝试使用 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,在这种情况下它没有被记录。谁能告诉我做错了什么?

最佳答案

您缺少一个yield。应该是:

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

关于javascript - Redux-Saga 调用不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48236735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com