使用React 16.8.6(在以前的版本16.8.3中很好),当我尝试调用封装方法时,出现此错误
React Hook useEffect has missing dependencies: 'CloseSignalRConnection' Either include them or remove the dependency array
解决办法:
一、将封装的方法放在useEffect中
useEffect(() => {
const CloseSignalRConnection = () => {
// code ...
}
CloseSignalRConnection()
}, [])
二、将关闭 ESLint 规则
useEffect(() => { // other code CloseSignalRConnection() // eslint-disable-next-line react-hooks/exhaustive-deps }, [])