Next.js Discord

Discord Forum

Is router.refresh() idiomatic?

Unanswered
Ruddy Duck posted this in #help-forum
Open in Discord
Ruddy DuckOP
When I have the choice between:
1. making a client component and leveraging things like tanstask query to query and update my backend + get fresh data on mutation
2. making a server component and leveraging server actions + router.refresh() to force refreshing the data on mutation

which one is better?

9 Replies

American Chinchilla
Depends, the first makes it hard for SSR
Second, i would say to use instead cache tags and server actions rather than API to keep ssr benefits; can check next docs on cache tags
@American Chinchilla Second, i would say to use instead cache tags and server actions rather than API to keep ssr benefits; can check next docs on cache tags
Ruddy DuckOP
Interesting, I did not know about cache tags. Is it the same concet as query keys kind of but for SSR?
It looks like it's very experimental though, I'm a bit worried about building on top of it if it gets removed in 2 months.
@American Chinchilla Can take a look at revalidateTag then
Ruddy DuckOP
Wait isn't cacheTag working along side revalidateTag? Also it looks like doing a revalidateTag will not trigger a data refresh immediately but only on the next page visite (which is why I was asking whether using router.refresh() often is considered an antipattern or not)
Ruddy DuckOP
This is react 14 but I assume still aplies to 15, will read