React Hook useEffect有一个缺失的依赖项:'dispatch'。要么包含它,要么删除依赖数组 react-hooks/exhaustive-deps
我在函数组件中使用了React Redux的useDispatch()
Hook,代码如下:
const Component = () => {
const dispatch = useDispatch();
const userName = useSelect(state => state.user.name);
useEffect(() => {
dispatch(getUserInformation());
}, [userId]);
return (
<div>Hello {userName}</div>
);
};
export default Component;
如何在不移除依赖数组 react-hooks/exhaustive-deps 的情况下解除此警告,该依赖数组可以帮助避免其他错误。