undefined 不是对象(评估 this.props.*AnActionIMade*) REACT-REDUX

undefined is not an object (evaluating this.props.*AnActionIMade*) REACT-REDUX

我使用 "this.props.UpdateInfo(values);"

调用操作

我使用了来自 react-redux 的 connect 并实现了它,如下所示:

我在网上看到可以使用 mapdispatchtoprops 但这也不起作用。 当我简单地使用 UpdateInfo(values) 调用它时它可以工作但是 return (dispatch) 没有被调用,里面没有任何东西被执行。

我也尝试了 this.props.dispatch(UpdateInfo(values) 但这也不起作用。

根据评论,代码如下。

 personalinfo.js

 Registration2Submit(values) {
  this.props.UpdateInfo(values);
} me calling the function this is where it errors

 const mapStateToProps = state => {
return {
 loading: state.ques.loading,
 };
};

 export default connect(mapStateToProps, { UpdateInfo }) 
(RegisterInfo);`
 //my mapping and connecting the action and component. 

myactioncreator.js 

export const UpdateInfo = (Obj) => {
const { currentUser } = firebase.auth();
console.log('got here 0');
return (dispatch) => {
    console.log('got here 1');
    dispatch({ type: VALIDATING });
    firebase.database().ref(`/users/${currentUser.uid}/userinfo`)
        .push(Obj)
  };
 };
 // this is the action. when i run it without the this.props the first 
 console log registers

原来忘记绑定Registration2Submit了。这修复了错误。

Registration2Submit = (values) => {
   this.props.UpdateInfo(values);
};