Next.js Discord

Discord Forum

`router.push('/sameRouteButWith?queryParam=new&another=new')` causes rerender?

Answered
Cuvier’s Dwarf Caiman posted this in #help-forum
Open in Discord
Cuvier’s Dwarf CaimanOP
Using App router.

Does pushing queryParams to the router for the current route cause the whole route and components to rerender? I wasn't quite sure from the docs.

Using App router.
Answered by gin
yes if u for example pass useSearchParams down to a child, the child will rerendender once the prop changes
View full answer

7 Replies

if u use the useSearchParams hook u can trigger a rerender based on that
whats the usecase?
Cuvier’s Dwarf CaimanOP
Ah, so does the useSearchParams hook cause the rerender if they have changed then?

Just a general question. I actually finally made progress on my use case after I stopped using multiple sources of truth for some values that are based off search params.
Answer
or u can have useEffect for the hook and idk update some data
Cuvier’s Dwarf CaimanOP
Okay, I see.

I wasn't sure if useSearchParams would cause a rerender on param change or just expose the changes when the component that calls useSearchParams() happens to rerender.

Thx for your insight!