react-navigation redux dispatch不是函数错误

时间:2018-05-03 10:57:55

标签: reactjs redux react-navigation

我在使用react-nativigation的react-native redux应用程序中收到错误,我有一个多阶段注册页面,在第一阶段完成后重定向。

重定向成功,但会显示以下错误。

Possible Unhandled Promise Rejection (id: 0):
TypeError: dispatch is not a function

我在承诺中呼叫发货,如下所示:

    export const registerUser = ({ email, username, password }) => (dispatch) => {
  dispatch({ type: REGISTER_USER_START });

  register(email, username, password)
    .then(() => {
        dispatch({ type: REGISTER_USER_SUCCESS });
        dispatch(NavigationActions.navigate({ routeName: 'RegisterDetails' }));
    })
    .catch((error) => {
      console.log('error', error);
      dispatch({ type: REGISTER_USER_FAIL })
  });
};

这些是我的路线

const AuthStack = StackNavigator({
  RegisterUser: { screen: RegisterUser },
  RegisterDetails: { screen: RegisterDetails },
  RegisterComplete: { screen: RegisterDetails },
  PasswordRecovery: {screen: PasswordRecovery}
});

const AppStack = StackNavigator({
  Landing: { screen: Landing }
});

const AppNavigator = SwitchNavigator({
  Auth: AuthStack,
  App: AppStack
},
{
  initialRouteName: 'Auth',
});

export default AppNavigator;

这是我的导航减速器

import AppNavigator from '../routes';
const INITIAL_STATE = AppNavigator.router.getStateForAction('RegisterUser');

export default (state = INITIAL_STATE, action) => {
    let nextState;

    switch (action.type) {
        default:
        nextState = AppNavigator.router.getStateForAction(action, state);
        break;
    }
    return nextState || state;
};

如果我点击后退按钮,应用程序崩溃,我收到以下错误 屏幕enter image description here

0 个答案:

没有答案