Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript this.props.getEvents不是函数_Javascript_Reactjs_Redux_React Redux - Fatal编程技术网

Javascript this.props.getEvents不是函数

Javascript this.props.getEvents不是函数,javascript,reactjs,redux,react-redux,Javascript,Reactjs,Redux,React Redux,我在我的eventActions.js中导出了中定义的getEvents。我不明白为什么会出现这个错误。我导入了函数,文件路径是正确的 组件 import { getEvents } from "../../actions/eventActions"; ... componentDidMount() { this.props.getCurrentProfile(); this.props.getEvents(); } eventActions.js // Get Events ex

我在我的
eventActions.js
中导出了中定义的getEvents。我不明白为什么会出现这个错误。我导入了函数,文件路径是正确的

组件

import { getEvents } from "../../actions/eventActions";

...

componentDidMount() {
  this.props.getCurrentProfile();
  this.props.getEvents();
}
eventActions.js

// Get Events
export const getEvents = () => dispatch => {
  dispatch(setEventsLoading());
  axios
    .get("/api/events")
    .then(res =>
      dispatch({
        type: GET_EVENTS,
        payload: res.data
      })
    )
    .catch(err =>
      dispatch({
        type: GET_EVENTS,
        payload: null
      })
    );
};

Props
是父组件传递给其子组件的东西。这里,您是从文件导入它,而不是从父组件传递


您可以简单地使用-
getEvents()
而不是
this.props.getEvents()

我没有用connect注入它。上述建议同样有效。我想我需要这个组件之外的东西,所以最好的选择是用connect注入它

export default connect(
  mapStateToProps,
  { getCurrentProfile, deleteAccount, getEvents }
)(Dashboard);

您正在将它导入到模块中,但您是否真的将
getEvents
作为组件的道具?试着只写
getEvents()取而代之。这很有效。为什么我可以调用
this.props.getCurrentProfile()
,但不能调用事件?谢谢你一直回答我的问题!不客气!如果看不到使用组件的代码,这很难说。使用组件时,您可能会将
getCurrentProfile
作为道具传入组件,或者您可能会使用Redux
connect
等注入组件。我没有使用connect注入它!事情就是这样!感谢您一如既往地放弃知识!为什么我可以使用
this.props.getCurrentProfile()
我试着像
getCurrentProfile()
那样调用它,但它没有加载?你和Thole的建议奏效了。因为,这可能是你在问题中提到的组件的父组件传递的。你能把代码贴在创建这个组件的地方吗?