Home > Mobile >  useEffect has a missing dependency: 'dispatch'
useEffect has a missing dependency: 'dispatch'

Time:03-25

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 !

CodePudding user response:

If you want to remove warnings like React Hook useEffect has a missing dependency: 'dispatch' then you can use eslint-disable-next-line in your useEffect.

useEffect(() => {
  if (!IsEmpty(loggedUser)) {
    dispatch(actions.getUserDetail({ userId: loggedUser.Sid }));
  }
  //eslint-disable-next-line
}, [loggedUser]);
  • Related