使用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 }, [])