Next.js Discord

Discord Forum

Updating Aysnc Search Params

Answered
Baird's Sandpiper posted this in #help-forum
Open in Discord
Baird's SandpiperOP
With the new async search params pattern, I am updating search params with NUQS (client component) and the url changes but do i have to force a refresh / reroute every time I update a search param to refetch on the page.ts ? As of now the value from the awaited search parameter does not change
Answered by B33fb0n3
when you need to update the page but also want to directly change the state, I would use nuqs and use nuqs's option to reload the page. The syntax for it is:
const [state, setState] = useQueryState('foo', { shallow: false })
View full answer

6 Replies

Baird's SandpiperOP
@B33fb0n3 thanks for the response. whats the best option in your opinion? use NUQS or just router.push(currentPathname) after update?
@Baird's Sandpiper <@301376057326567425> thanks for the response. whats the best option in your opinion? use NUQS or just router.push(currentPathname) after update?
when you need to update the page but also want to directly change the state, I would use nuqs and use nuqs's option to reload the page. The syntax for it is:
const [state, setState] = useQueryState('foo', { shallow: false })
Answer
Asian black bear
useQuery(somethingParser, {
    shallow: false, // This forces RSCs to reload
})
@Baird's Sandpiper solved?