【发布时间】:2021-05-19 11:26:57
【问题描述】:
在 TypeScript 中使用 useEffect 时,未将函数添加为依赖项会显示警告。
const dispatch = useDispatch()
useEffect(() =>{
if(isAuthenticated){
history.push('/dashboard')
}
// eslint-disable-next-line react-hooks/exhaustive-deps
},[isAuthenticated])
我目前正在使用 // eslint-disable-next-line react-hooks/exhaustive-deps。 我知道这样做不好。但它也要求我添加功能。我应该在 useEffect 中添加功能吗?
以及如何将componentDisMount作为[]作为依赖也会导致ts错误
useEffect(() => {
getFeaturedJobs();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
【问题讨论】:
-
请阅读How to create a Minimal, Reproducible Example。目前还不清楚
reauthenticate在代码中的位置以及它有什么依赖关系。我的猜测是,它需要一些组件状态。
标签: reactjs typescript react-tsx