useEffect(() => {
if (jwt !== null) {
history.push("/");
}
}, [jwt]);
老师,对于上面的代码,项目运行时会提示警告,如下,貌似提示需要把history也放入 useEffect的依赖中,但是history应该不会变化把,怎么去除这种警告呢。
src/pages/signIn/SignInForm.tsx
Line 29:6: React Hook useEffect has a missing dependency: 'history'. Either include it or remove the dependency array react-hooks/exhaustive-deps
还有这里也有,提示需要把dispatch 和 keywords 放入。
useEffect(() => {
dispatch(
searchProduct({
nextPage: 1,
pageSize: 10,
keywords,
})
);
}, [location]);
src/pages/search/SearchPage.tsx
Line 33:6: React Hook useEffect has missing dependencies: 'dispatch' and 'keywords'. Either include them or remove the dependency array react-hooks/exhaustive-deps
React18 精讲 + 结合 TS 实战 + 热门业务开发,获取必备技能
了解课程