Initial value
💡
Use zod's .default()
method to set the initial value for the property.
const { data, setState, setValue } = useUrlState(
z.object({
search: z.string().default('initial-value'),
limit: z.coerce.number().max(100).default(1),
from: z.coerce.date().default(new Date('1000-01-01')),
}),
);
return (
<ButtonsGroup>
<Button
onClick={() =>
setState({
search: 'query',
limit: 10,
from: new Date(),
})
}
>
Set the state
</Button>
</ButtonsGroup>
);
State
null