Nuqs
Unanswered
Cape horse mackerel posted this in #help-forum
Cape horse mackerelOP
Hello guys.
Any nuqs "users" here?
I'm trying to replace my search params with nuqs and having some issues.
I've built queries via Zod and infering types from Zod schema, but don't know how to write that down in nuqs.
Any nuqs "users" here?
I'm trying to replace my search params with nuqs and having some issues.
I've built queries via Zod and infering types from Zod schema, but don't know how to write that down in nuqs.
// schema
const getRequestSchema = z.object({
status: "APPROVED" | "PENDING" | "REJECTED",
pagination: {
page: z.coerce.number().optional(),
perPage: z.coerce.number().optional()
}
});
export type GetRequest = z.infer<typeof getRequestSchema>
// nuqs hook
function useGetRequestParams(pageDefault: number, perPageDefault: number) {
return useStateQuery</*is there a way to tell nuqs that this should be GetRequest type*/>({
status: "PENDING",
/*
getting errors when doing object initialization
pagination: {
page: parseAsInteger.withDefault(pageDefault),
perPage: parseAsInteger.withDefault(perPageDefault),
}
*/
// this works but doesn't match my payload
page: parseAsInteger.withDefault(pageDefault),
perPage: parseAsInteger.withDefault(perPageDefault),
});
}
// my-component.tsx
const [params, setParams] = useGetRequestParams(1, 10);