react ESlint警告: React Hook useEffect has a missing dependency

问题
在使用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注释,忽略掉


react ESlint警告: React Hook useEffect has a missing dependency_第1张图片
image.png

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

你可能感兴趣的:(react ESlint警告: React Hook useEffect has a missing dependency)