【发布时间】:2020-09-26 04:36:37
【问题描述】:
为什么缺少依赖问题
const [ comments, setComment ] = useState([])
const fetchComments = async () => {
const res = await axios.get(`http://localhost:4001/posts/${postid}/comments`);
setComment(res.data);
}
useEffect(() => {
fetchComments();
}, [postid]);
console.log("IsArray", Array.isArray(comments)); // Returns me true, true, true then warning after warning it become false, false
为什么会有这样的行为我对帖子列表采用了相同的方法,它确实可以正常工作,但是使用特定 ID 获取它会向我发送错误。请指导
【问题讨论】:
标签: reactjs react-hooks