Skip to content

Support the useQueryState type generic argument with parser withDefault. #477

Answered by franky47
ronny1020 asked this question in Ideas
Discussion options

You must be logged in to vote

You'll need the parser to be a bit smarter about the runtime value if you want to achieve type-safety. The string parser doesn't check values (it doesn't do anything actually, it's a pass-through).

What you want is the parseAsStringLiteral parser:

const orderByDirection = ['asc', 'desc'] as const;
export type OrderByDirection = (typeof orderByDirection)[number];

const [direction, setDirection] = useQueryState(
   'direction',
    parseAsStringLiteral(orderByDirection).withDefault('desc')
);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by franky47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants