I have scoured the internet for answers to no avail. It's baffling because I expected this issue to be quite common.
Take, for instance, the scenario where we need to retrieve a post with a specific id:
const { data } = useSWR(`/api/post/${id}`, fetcher)
Let's say we also have a form that allows us to edit the post. Upon mutating:
mutate(`/api/post/${id}`)
However, when attempting to force revalidation on a particular id, nothing seems to happen. How can this be resolved in the correct manner?
On another note, performing SWR fetching without an id like using /api/comments
, which fetches all comments, seems to work flawlessly when executing mutate('/api/comments')
.
I hope my explanation is coherent. Essentially, what I aim to accomplish is making a POST request after updating a post with a specific id and seamlessly refreshing the page with the updated information.
It appears that mutate fails to recognize the key when the id value is dynamic.