react ESlint警告: React Hook useEf

2021-03-05  本文已影响0人  折叠幸福

问题
在使用useEffect时,当我们将函数的声明放在useEffect函数外面时
或者使用useState定义的历史变量,会报eslint警告

webpackHotDevClient.js:119 ./src/pages/detail/enterprise/modules/businessWarning/modules/tendAndBid/modules/topTitle/index.jsx
  Line 27:6:  React Hook useEffect has a missing dependency: 'menuConfig'. Either include it or remove the dependency array. You can also do a functional update 'setMenuConfig(m => ...)' if you only need 'menuConfig' in the 'setMenuConfig' call  react-hooks/exhaustive-deps

解决办法
1.在useEffect后面加个eslint注释,忽略掉


image.png

2.如果是函数,将函数放在useEffect内部,如果是变量,用deepcopy拷贝useSet定义的变量或者采用useRef

上一篇 下一篇

猜你喜欢

热点阅读