Javascript 双redux调度,即使在if和mount上运行,即使状态为空
我有一个useEffect,每次我更改updateId时都会检查它,updateId是每个帖子的一个按钮,但由于某些原因,它会在mount上运行,每次我单击按钮时都会运行2次 这是我的效果Javascript 双redux调度,即使在if和mount上运行,即使状态为空,javascript,reactjs,redux,react-redux,Javascript,Reactjs,Redux,React Redux,我有一个useEffect,每次我更改updateId时都会检查它,updateId是每个帖子的一个按钮,但由于某些原因,它会在mount上运行,每次我单击按钮时都会运行2次 这是我的效果 useEffect(() => { if (posts.length === 0) { dispatch(listPosts()); } else { if (!post || post._id !== updateId) { dispatch(l
useEffect(() => {
if (posts.length === 0) {
dispatch(listPosts());
} else {
if (!post || post._id !== updateId) {
dispatch(listPostDetails(updateId));
} else {
setDescription(post.description);
setImage(post.image);
setTitle(post.title);
}
}
}, [dispatch, posts.length, updateId, setUpdateId, post]);
出于某种原因,它在请求中以%3Canonymous%3E的形式发送,即使我将我的useState初始状态设置为null或“”,为什么在useEffect的第二个参数中使用
setUpdateId
?