Hi,
I have a page containing posts data (using SWR).
The user can click on "edit post" and it will redirect him to another edit page.
After editing success, the user is getting redirect back to the posts page.
Than, for a second, it sees the old data (before the edit), and after auto revalidation on mount, the new data arrives and the user can see the real data.
How can I prevent it from using the cache on mount in order not to show the user false data?
thanks
What you need to do is use mutate to update the cache before the page navigation
@sergiodxa how do we use mutate? and how do we use it with "useSWRPages" ?
@rafinskipg you can import mutate from swr as
import { mutate } from 'swr'
Then you can call it as mutate(key, newDate), it also support a function as mutate(key, oldData => newDate), additionally you can pass a false as third value to avoid mutate to revalidate the data and only update it (by default mutate after updating the cached data it will trigger a new revalidation to ensure it's consistent with the backend)
Most helpful comment
What you need to do is use mutate to update the cache before the page navigation