您将返回
getResponse()从
useEffect函数调用的结果。如果您从中返回任何内容
useEffect,则它必须是一个函数。将代码更改为此应该可以解决该问题,因为您不再从该
useEffect函数返回任何内容。
useEffect(() => { getResponse();});该useEffect
清理功能
如果从
useEffecthook函数返回任何内容,则它必须是 cleanup函数
。卸载组件时将运行此功能。可以认为这
componentWillUnmount与类组件中的生命周期方法大致等效。
useEffect(() => { doSomething(); return () => { console.log("This will be logged on unmount"); }});


