UNPKG

@getaround-eu/use-route-params

Version:

A hook to get typed params from route

7 lines (6 loc) 628 B
declare type NonNullableKeys<T> = { [P in keyof T]-?: NonNullable<T[P]>; }; declare type PathParamsLiteral<S extends string> = S extends `:${infer T}/${infer U}` | `/:${infer T}/${infer U}` ? T | PathParamsLiteral<U> : S extends `${infer _T}/${infer U}` ? PathParamsLiteral<U> : S extends `:${infer T}` | `/:${infer T}` ? T : never; declare const useRouteParams: <RoutePath extends string>(_path: RoutePath) => NonNullableKeys<Readonly<[PathParamsLiteral<RoutePath>] extends [string] ? import("react-router-dom").Params<PathParamsLiteral<RoutePath>> : Partial<PathParamsLiteral<RoutePath>>>>; export default useRouteParams;