Multiple dynamic requests caching #1117
Unanswered
eliascotto
asked this question in
Q&A
Replies: 2 comments 1 reply
-
The error reports
with this code const router = useRouter()
const { ids } = router.query
const [resources, setResources] = useState([])
let otherResources = []
if (resourcesX) {
otherResources = { ...resources.map((resId) => {
// I suppose that the cache works so just new resources are fetched
return useSWR(`/resources/${resId}`, fetch)
})}
}
useEffect(() => {
if (ids) {
if (Array.isArray(ids)) {
setResources(ids)
} else {
setResources([ids])
}
}
}, [ids]) |
Beta Was this translation helpful? Give feedback.
0 replies
-
I hope #1041 might be helpful for your problem |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
supposing that I've a route with a query parameter that allow multiple values
which turn the router value as
I want to fetch every resource with specified
id
but maintaining the cache provided by SWR. So every time I add anid
as query param I need to fetch only the new resource and when I remove a resource no request is performed. If the user edit the query parameters adding 100 new ids, the app should fetch all of them (if they're not cached).I've read the tutorial here but they advise to better moving the request into the component representing the resource. But I need to have all of them together.
This is my final version but lead to error anyway
Beta Was this translation helpful? Give feedback.
All reactions