Auto update params in next js #1061
Answered
by
franky47
Shitanshukumar607
asked this question in
Q&A
|
Hey Im using nuqs version <Input
placeholder="Search companions..."
className="outline-none pl-8"
value={topic}
onChange={(e) => setTopic(e.target.value || null)}
/>and im updating the serach params like this const [topic, setTopic] = useQueryState("topic", {
defaultValue: "",
});and in my server component im trying to call a function whenever the search params get changed. type PageProps = {
searchParams: Promise<SearchParams>;
};
const CompanionLibrary = async ({ searchParams }: PageProps) => {
const { subject, topic } = await loadSearchParams(searchParams);
console.log("topic is", topic);
const companions = await someFunc({ topic });
//rest of the codeand created the searchParams file as mentioned on the same site import { createLoader, parseAsString } from "nuqs/server";
export const coordinatesSearchParams = {
topic: parseAsString.withDefault(""),
};
export const loadSearchParams = createLoader(coordinatesSearchParams);But even after doing this whenever i write in the input element the search params get updated but the console log gives an empty string which was logged when the application was started after that there is no log about the topic
|
Answered by
franky47
Aug 13, 2025
Replies: 1 comment
|
Set the Docs: https://nuqs.47ng.com/docs/options#shallow const [topic, setTopic] = useQueryState("topic", {
defaultValue: "",
shallow: false
}); |
0 replies
Answer selected by
franky47
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Set the
shallowoption tofalsein your hook to notify the server on updates:Docs: https://nuqs.47ng.com/docs/options#shallow