Implementing Search Functionality in nuqs #651
Replies: 3 comments
-
Sorry, I think this applies, so I'll close this discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hmm, after all, The logic for retaining parameters other than query when on a search page (as noted in the comments) isn't working well (maybe I need to use URLSearchParams?). I'd appreciate it if you could teach me the best practices 🙏 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Would an implementation like this be a good idea...? export function SearchForm( ) {
const searchParams = useSearchParams();
const t = useTranslations('common');
const tSr = useTranslations('common-sr');
const router = useRouter();
const [isPending, startTransition] = useTransition();
const queryParser = parseAsString.withDefault('').withOptions({
startTransition,
});
const { register, handleSubmit } = useSearchForm();
const onSubmit = ({ query }: SearchFormSchema) => {
const serialize = createSerializer({
query: queryParser,
});
const newSearchParams = new URLSearchParams(searchParams);
const url = serialize(newSearchParams, { query });
router.push(`/search${url}`);
};
return <></>
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have currently implemented the search functionality as follows:
I have moved this implementation from the root path to the /search path and want to use the query search parameter to fetch the search results.
I'm trying to achieve this in nuqs without using useRouter, usePathname, or useSearchParams, but it's not working as expected.
Is there a good way to implement this functionality in nuqs without relying on these hooks?
Beta Was this translation helpful? Give feedback.
All reactions