Skip refetch when changing searchParams
Answered
Florian posted this in #help-forum
FlorianOP
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?
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
7 Replies
@Florian 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?
Hmm try making an intermediate layout with the categories in there, and the page only includes the search result
Answer
@joulev Hmm try making an intermediate layout with the categories in there, and the page only includes the search result
FlorianOP
Yea this was my idea too. I was just wondering if there was a simpler way 🤔 guess not then
FlorianOP
Thank you, it works 👌
@Florian 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?
do you also need it to be client-component free?
FlorianOP
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 
@ᴉuɐpɹɐɐ could also check out `nuqs` and experience that sweet sweet shallow routing from changing search param <:kgsDuckTasty:754871636687192155>
FlorianOP
Looks interesting. I might check it out.