javascript - this.props.getEvents 不是函数
问题描述
我在导出的eventActions.js
. 我无法弄清楚为什么会收到此错误。我导入了函数,文件路径是正确的。
零件
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()
.
推荐阅读
- java - 在确保 value 不为 null 后使用 BufferedReader 时,如何防止在 Java 中发生空指针异常?
- compiler-errors - mpifort -DMPI 编译错误:派生类型“mpi_status”用作实际参数。适用于英特尔 Fortran,但不适用于 GNU Fortran
- javascript - 即使垂直滚动条位于顶部,如何使水平滚动条始终可见
- javascript - 位置 div 之间的空间:相对
- javascript - 嵌套对象数组的 Javascript 解决方法
- c++ - 如何使用 C++ 在 OpenCV 4.2.0 中使用 SIFT?
- java - Java:glScissor 多边形
- pyspark - 如何从pyspark中的xml读取嵌套元素?
- sequelize.js - 查找嵌套包含匹配所有内容的行
- javascript - 调用大于 x 长度的单词的方法