Abhishek kamal
Abhishek kamal

Reputation: 329

useEffect has a missing dependency: 'dispatch'

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 !

Upvotes: 0

Views: 754

Answers (1)

Dharmik Patel
Dharmik Patel

Reputation: 1201

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]);

Upvotes: 2

Related Questions