我在 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()
。
关于javascript - this.props.getEvents 不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51685867/