小编Ign*_*cio的帖子

How to fix React Redux and React Hook useEffect has a missing dependency: 'dispatch'

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

I use useDispatch() Hook from React Redux on a functional component like this:

const Component = () => {
  const dispatch = useDispatch();
  const userName = useSelect(state => state.user.name);

  useEffect(() => {
    dispatch(getUserInformation());
  }, [userId]);

  return (
    <div>Hello {userName}</div>
  );
};

export default Component;
Run Code Online (Sandbox Code Playgroud)

How to remove this warning without removing the dependency array react-hooks/exhaustive-deps which can be useful to avoid other errors.

javascript reactjs react-redux react-hooks use-effect

3
推荐指数
1
解决办法
2297
查看次数