Ani*_*nde 12 reactjs react-hooks
谁能帮我摆脱这个警告
React Hook useEffect 缺少依赖项:“dispatch”。包含它或删除依赖项数组react-hooks/exhaustive-deps
这是我的代码
Run Code Online (Sandbox Code Playgroud)function Register(props) { const inusers=useSelector( (state) => {return state}); const history=useHistory() const dispatch=useDispatch(); // const formik = useFormikContext(); useEffect( () => { dispatch(fetchUser()) },[])
And*_*zo1 23
只需在依赖项中添加调度:
useEffect(() => {
dispatch(fetchUser())
},[dispatch])
Run Code Online (Sandbox Code Playgroud)
Dispatch 是一个安全的添加依赖项,它不会导致无限循环。有关调度为何可以更改(以及何时可以更改)的更多见解,请检查:
更新:来自react-redux文档
| 归档时间: |
|
| 查看次数: |
20016 次 |
| 最近记录: |