-
Currently, when I change the search params using My use case is, I have two states stored in the URL search params:
The problem is the component with the second state ( UPDATE New import { subscribeToQueryUpdates } from 'next-usequerystate'
import { useSearchParams } from 'next/navigation'
import { useLayoutEffect, useState } from 'react'
export function useReactiveSearchParams() {
const defaultSearchParams = useSearchParams()
const [searchParams, setSearchParams] =
useState<URLSearchParams>(defaultSearchParams)
useLayoutEffect(() => {
subscribeToQueryUpdates(({ search }) => {
setSearchParams(search)
})
}, [])
return searchParams
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
As discussed in #400 (comment), |
Beta Was this translation helpful? Give feedback.
As discussed in #400 (comment),
useSearchParams
is not (yet) reactive of shallow URL changes, which is the default update mechanism.