{getDataFun} 和 React Hook useEffect 有一个依赖项: getDataFun 。 为什么没问题?
const { getDataFun } = props;
useEffect(() => {
getDataFun();
}, [getDataFun]);
React Hook useEffect 有一个依赖项:props.getDataFun。 为什么有警告???
useEffect(() => {
props.getDataFun();
}, [props.getDataFun]); // why missing dependency: 'props'???
// React Hook useEffect has a missing dependency: 'props'.
// Either include it or remove the dependency array.
// However, 'props' will change when *any* prop changes,
// so the preferred fix is to destructure the 'props'
// object outside of the useEffect call and refer to
// those specific props inside useEffect.
遵循提示依赖项:'props'。但是 getDataFun 无限循环
useEffect(() => {
props.getDataFun();
}, [props]);