useEffect 缺少依赖项:“dispatch”
我正在使用 Reactjs 和 Redux。
//constants
const dispatch = useDispatch();
//useEffects
useEffect(() => {
if (!IsEmpty(loggedUser)) {
dispatch(actions.getUserDetail({ userId: loggedUser.Sid }));
}
}, [loggedUser]);
一切正常。但我在浏览器控制台中收到警告:
src/components/EditProfile.js 第 91:6 行:React Hook useEffect 缺少依赖项:“dispatch”。要么包含它,要么删除依赖数组react-hooks/exhaustive-deps
我不知道如何删除此警告。
请帮我 !
I am using Reactjs and Redux.
//constants
const dispatch = useDispatch();
//useEffects
useEffect(() => {
if (!IsEmpty(loggedUser)) {
dispatch(actions.getUserDetail({ userId: loggedUser.Sid }));
}
}, [loggedUser]);
Everything is working fine. But I am getting a warning in browser's console :
src/components/EditProfile.js
Line 91:6: React Hook useEffect has a missing dependency: 'dispatch'. Either include it or remove the dependency array react-hooks/exhaustive-deps
I don't know how can I remove this warning.
Please help me !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想删除诸如
React Hook useEffect has a Missing dependency: 'dispatch'
之类的警告
,那么您可以使用eslint-disable-next-line
在您的useEffect
中。If you want to remove
warnings
likeReact Hook useEffect has a missing dependency: 'dispatch'
then you can useeslint-disable-next-line
in youruseEffect
.