-
DescriptionI want to update the
type PageProps = {
searchParams: {
q: string
}
}
export default async function Page(props: PageProps) {
return (
<>
<h1>{props.searchParams.q}</h1>
<SearchInput />
</>
)
}
'use client'
import { Search } from '@carbon/react'
import { useQueryState } from 'next-usequerystate'
export function SearchInput() {
const [unsafeValue, setValue] = useQueryState('q')
const value = unsafeValue || undefined
return (
<Search
labelText
value={value}
onChange={(e) => {
setValue(e.target.value)
}}
></Search>
)
} I've tested the code above but it didn't work. Server Component did not re-render. My Stack |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Try this: const [unsafeValue, setValue] = useQueryState('q')
.withOptions({ shallow: false })
.withDefault('') // May I recommend this change too, to turn null into empty strings and simplify logic later Shallow mode is on by default (client-only updates), you have to opt-in to notifying the server. If you are connecting this to a database query, you might want to run the parser on the server too. FYI, for high-frequency updates like text inputs, you won't receive a request per character typed. Instead, they'll be batched and throttled at around 50ms. This should help avoid overloading your server and/or database. |
Beta Was this translation helpful? Give feedback.
Try this:
Shallow mode is on by default (client-only updates), you have to opt-in to notifying the server.
If you are connecting this to a database query, you might want to run the parser on the server too.
FYI, for high-frequency updates like text inputs, you won't receive a request per character typed. Instead, they'll be batched and throttled at around 50ms. This should help avoid overloading your server and/or database.