我想把它转换成一个函数组件
这是在使用React库,我相信我大部分都是正确的。我认为这与fetchDraftsTimer函数有关,但我不能完全确定我遗漏了什么。
import React from 'react';
class MyComponent extends React.Component(props) {
componentDidMount() {
this.props.fetchDrafts()
this.props.fetchHistory()
this.fetchDraftsTimer = setInterval(() => {
this.props.fetchDrafts();
}, 120000);
}
render() {
return null;
}
}我做过这样的事
import React, { useEffect } from "react";
export default function MyComponent(props) {
useEffect(() => {
props.fetchDrafts;
props.fetchHistory;
setInterval(() => {
props.fetchDrafts;
}, 120000);
return () => {
};
}, []);
return null;
}我是不是遗漏了什么?显然,这两种方法都缺少一些逻辑。请帮帮我!
发布于 2021-06-11 03:40:25
props.fetchHistory;
props.fetchDrafts;您必须调用这些函数,就像在类组件中一样。只有当你想将这个函数本身传递给子组件时,你才应该使用上面的方法。
props.fetchHistory();
props.fetchDrafts();https://stackoverflow.com/questions/67927400
复制相似问题