Skip to content
Discussion options

You must be logged in to vote

Yes that would work.

Another tip, if you want to avoid repeating key names and parser config, you can use the same searchParams declaration object for both the serializer and the useQueryStates hook:

"use client";
import Link from "next/link";
import { createSerializer, parseAsString, useQueryStates } from "nuqs";

const searchParams = {
  name: parseAsString,
};

const serialize = createSerializer(searchParams);

export const ColorPicker = () => {
  const [{name}] = useQueryStates(searchParams);

  return (
    <>
      <p>{name}</p>
      <Link href={serialize({ name: "Lars" })}>Set name to Lars.</Link>
    </>
  );
};

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@LarsFlieger
Comment options

@franky47
Comment options

Answer selected by LarsFlieger
@LarsFlieger
Comment options

Comment options

You must be logged in to vote
1 reply
@franky47
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants