Next.js Discord

Discord Forum

Skip refetch when changing searchParams

Answered
Florian posted this in #help-forum
Open in Discord
On this server component page, search is handled by pushing the query to the URL search param (via router).

Both the categories and the results (orange boxes) are fetched from the DB. How can I avoid re-fetching the categories every time the search query changes?
Answered by joulev
Hmm try making an intermediate layout with the categories in there, and the page only includes the search result
View full answer

7 Replies

Answer
@joulev Hmm try making an intermediate layout with the categories in there, and the page only includes the search result
Yea this was my idea too. I was just wondering if there was a simpler way 🤔 guess not then
Thank you, it works 👌
Not necessarily, but the layout approach works
@Florian Not necessarily, but the layout approach works
could also check out nuqs and experience that sweet sweet shallow routing from changing search param :kgsDuckTasty: