0
votes

How can I fix this warning?

React Hook useEffect has a missing dependency: 'loading'. Either include it or remove the dependency array react-hooks/exhaustive-deps.

  useEffect(() => {
    if (!loading && data) {
      dispatch(action.TODO(data));
    }
  }, [data, dispatch]);

2
It tells you how to fix it: Either include loading to your dependency array or remove the array.tkausl

2 Answers

1
votes

You add a dependency to a useEffect hook by specifying it in the second argument array.

Like this.

useEffect(() => {
  if (!loading && data) {
     dispatch(action.TODO(data));
  }
}, [data, dispatch, loading]);
1
votes

The short answer is: in the array of the second parameter of useEffect remove dispatch and add loading

The correct answer is: When useEffect uses a variable as a conditional inside its execution, it considers it a dependency, and indicates that it should be executed again when it is being modified, otherwise it must be eliminated from the dependencies array