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

  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2023-03-03
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
  • 2021-09-20
  • 2021-09-06
  • 1970-01-01
相关资源
相似解决方案