useEffect 缺少依赖项:'dispatch'
useEffect has a missing dependency: 'dispatch'
我正在使用 Reactjs 和 Redux。
//constants
const dispatch = useDispatch();
//useEffects
useEffect(() => {
if (!IsEmpty(loggedUser)) {
dispatch(actions.getUserDetail({ userId: loggedUser.Sid }));
}
}, [loggedUser]);
一切正常。但是我在浏览器的控制台中收到警告:
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
我不知道如何删除这个警告。
请帮助我!
如果您想像 React Hook useEffect has a missing dependency: 'dispatch'
一样删除 warnings
,那么您可以在 useEffect
.
中使用 eslint-disable-next-line
useEffect(() => {
if (!IsEmpty(loggedUser)) {
dispatch(actions.getUserDetail({ userId: loggedUser.Sid }));
}
//eslint-disable-next-line
}, [loggedUser]);
我正在使用 Reactjs 和 Redux。
//constants
const dispatch = useDispatch();
//useEffects
useEffect(() => {
if (!IsEmpty(loggedUser)) {
dispatch(actions.getUserDetail({ userId: loggedUser.Sid }));
}
}, [loggedUser]);
一切正常。但是我在浏览器的控制台中收到警告:
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
我不知道如何删除这个警告。
请帮助我!
如果您想像 React Hook useEffect has a missing dependency: 'dispatch'
一样删除 warnings
,那么您可以在 useEffect
.
eslint-disable-next-line
useEffect(() => {
if (!IsEmpty(loggedUser)) {
dispatch(actions.getUserDetail({ userId: loggedUser.Sid }));
}
//eslint-disable-next-line
}, [loggedUser]);