error:‘React Hook useEffect has a missing dependency:’

发布于 2022-09-13 01:16:12 字数 1513 浏览 37 评论 0

react报错
需要忽略这个警告吗?

src\page\home\deviceList\deviceList.jsx
  Line 94:6:  React Hook useEffect has a missing dependency: 'getgatewaydevice'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

src\page\home\gatewayConfig\gatewayConfig.jsx
  Line 35:6:  React Hook useEffect has a missing dependency: 'props.history'. Either include it or remove the dependency array  react-hooks/exhaustive-deps


src\page\home\gatewayInfo\gatewayInfo.jsx
  Line 70:17:  Assignments to the 'setTime' variable from inside React Hook useEffect will be lost after each render. To preserve the value over time, store it in a useRef Hook and keep the mutable value in the '.current' property. Otherwise, you can move this variable directly inside useEffect  react-hooks/exhaustive-deps
  Line 80:6:   React Hook useEffect has a missing dependency: 'history'. Either include it or remove the dependency array                                                                                                                                                                                react-hooks/exhaustive-deps

src\page\home\gatewayInfo\upgrade\upgrade.tsx
  Line 27:6:  React Hook useEffect has a missing dependency: 'show'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

src\page\home\home.jsx
  Line 89:5:  React Hook useEffect has a missing dependency: 'props'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷清清 2022-09-20 01:16:12

在仔细看看文档:

1.https://reactjs.org/docs/hook... effects每次更新都会执行

2.https://reactjs.org/docs/hook... 如何利用依赖列表来跳过effect

3.结尾还有一大段note,非常有用

总结:可以忽略,前提是你能准确的保证每个effect都在准确的实际被执行。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文