Skip to content

Data only refeshs after reloading the page #790

Answered by NikRoe
PeetThesing asked this question in Web
Discussion options

You must be logged in to vote

Hi there,

the one and only @onemanwenttomow was able to find a better solution!

Your approach with using mutate was the absolute right one, however, you need to make a very small adjustment to it:
in your handleDelete in SnippetDetailsPage you need to add a slash to the string.

mutate(`/api/snippets`);

The reason behind this is that this string needs to be identical to the URL string of your fetch in the _app.js to actually case swr to revalidate the data.

In your createSnippet in FormPage you can call mutate() without passing an argument to it.
Since you destructure it from the return of useSWR("/api/snippets"); it will always revalidate the URL you specified here.

Hope this already make…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@NikRoe
Comment options

Answer selected by PeetThesing
@PeetThesing
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
2 participants