我有一个包含 3 个依赖项的 useEffect 钩子
useEffect(() => {
const params = { ...filter, limit: limit, skip:skip }
console.log("============ FROM USE EFFECT =============", params)
fetch(`http://localhost:8000/api/v1/posts?${stringify(params)}`)
.then(res => {
console.log(res);
if (!res.ok) {
throw Error('could not fetch the data for that resource');
}
return res.json();
})
.then(data => {
if(cases)setCases([...cases,...data])
else setCases(data)
setIsPending(false)
})
.catch(err => {
console.log(err);
})
}, [filter, limit, skip]);
我想如果过滤器依赖项发生变化,我想将限制和跳过状态设置为其他一些值