Initial value
💡
Initial value is applied on initial load.
const { data, setState, setValue } = useUrlState(
z.object({
search: z.string(),
limit: z.coerce.number().max(100),
from: z.coerce.date().optional(),
}),
{
search: 'init',
limit: 1,
from: new Date('1000-01-01'),
},
);
return (
<ButtonsGroup>
<Button
onClick={() =>
setState({
search: 'query',
limit: 10,
from: new Date(),
})
}
>
Set the state
</Button>
</ButtonsGroup>
);
State
{ "search": "init-not-apply", "limit": 1, "from": "1000-01-01T00:00:00.000Z" }