React Hook Useffect对于空数组依赖性缺失了依赖性
我缺少依赖性警告。
React Hook UseFect的依赖性缺失:'FetchFeatured'。包括它,要么删除依赖项数组
我的代码
useEffect(() => {
const fetchFeatured = () => {
onSnapshot(faeturedCollectionRef, (snapshot) =>
setFeatured(snapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id })))
)
}
fetchFeatured();
}, [])
我已经使用空数组来避免循环。
I am getting missing dependency warning.
React Hook useEffect has a missing dependency: 'fetchFeatured'. Either include it or remove the dependency array
My Code
useEffect(() => {
const fetchFeatured = () => {
onSnapshot(faeturedCollectionRef, (snapshot) =>
setFeatured(snapshot.docs.map((doc) => ({ ...doc.data(), id: doc.id })))
)
}
fetchFeatured();
}, [])
I have used empty array for avoiding loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过这样的评论来避免警告
you can avoid the waring by disabling it with a comment like this
该警告的主要目的是防止开发人员在其效果中缺失依赖性,并失去某些行为或意想不到的效果。在这种情况下,您可以
.eslintrc
文件,然后更改'react-hooks/afterive-deps':'warn'
'react-hooks /详尽的deps':'off'
The main purpose of the this warning is to prevent the developers from missing dependencies inside their effect and lost some behavior or unintended effect. In this case, you can
.eslintrc
file and change'react-hooks/exhaustive-deps': 'warn'
to'react-hooks/exhaustive-deps': 'off'