Is router.refresh() idiomatic?
Unanswered
Ruddy Duck posted this in #help-forum
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?
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
Netherland Dwarf
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
@Netherland Dwarf 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.
@Ruddy Duck Interesting, I did not know about cache tags. Is it the same concet as query keys kind of but for SSR?
Netherland Dwarf
Yeah similar to query keys
@Ruddy Duck 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.
Netherland Dwarf
Can take a look at revalidateTag then
@Netherland Dwarf 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 Duck 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)
Netherland Dwarf
See https://nextjs.org/docs/14/app/building-your-application/data-fetching/fetching-caching-and-revalidating on demand revalidatiob
Ruddy DuckOP
This is react 14 but I assume still aplies to 15, will read