-
Is this valid use? : const ItemSchema = z.object({
id: z.string(),
groupId: z.string(),
});
export function usePurchasedItems() {
const [purchasedItems, setPurchasedItems] = useQueryState(
"item",
parseAsArrayOf(parseAsJson(ItemSchema.parse))
);
return [purchasedItems, setPurchasedItems] as const;
} typesense seems to recognize it as valid but I want to make sure. I'm getting nulls when trying to read from the array. |
Beta Was this translation helpful? Give feedback.
Answered by
franky47
Oct 14, 2024
Replies: 1 comment 1 reply
-
The const [purchasedItems, setPurchasedItems] = useQueryState(
"item",
parseAsArrayOf(parseAsJson(ItemSchema.parse)).withDefault([])
); Now be aware that URLs are user input: I don't know what your exact use-case is, but know that users can (and will) modify URLs, so in your case, they could add, remove, or edit purchased items. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
mhddngs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
purchasedItems
type here isz.infer<typeof ItemSchema> | null
, because there can be noitem
key in the URL. To prevent that, set a default value:Now be aware that URLs are user input: I don't know what your exact use-case is, but know that users can (and will) modify URLs, so in your case, they could add, remove, or edit purchased items.