Replies: 2 comments 5 replies
-
I think this is a potentially great value add. This will mean you don't need to do any |
Beta Was this translation helpful? Give feedback.
-
I'm not sure I see any benefit when moving from: const { state } = useLocation() as Location<State>; versus: const { state } = useLocation<State>(); Is it just about removing some extra keystrokes? They'd be functionally identical. The main thing I worry about would be the implication that there's some kind of guarantee that I think something with stronger guarantees could be useful here: function useLocation<T = unknown>(validateState?: (state: unknown) => T): T; or possibly even leveraging Standard Schema to allow for something like: import { z } from 'zod';
const StateSchema = z.object({ id: z.number() })
.or(z.undefined());
const { state } = useLocation(StateSchema);
// ^? { id: number } | undefined |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently,
useLocation
is non-generic, and the state data returned by it is simply typed asany
.The
Location
type already supports state typing, so it should be trivial to implement a generic foruseLocation
.Beta Was this translation helpful? Give feedback.
All reactions