Skip to content

Commit

Permalink
Improve the type of useParams (#8352)
Browse files Browse the repository at this point in the history
Co-authored-by: 侯宗楠 <houzn@go-goal.com>
  • Loading branch information
2 people authored and timdorr committed Dec 3, 2021
1 parent 11aad9d commit 1108f1c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/react-router/index.tsx
Expand Up @@ -526,8 +526,10 @@ export function useOutlet(): React.ReactElement | null {
*
* @see https://reactrouter.com/docs/en/v6/api#useparams
*/
export function useParams<Key extends string = string>(): Readonly<
Params<Key>
export function useParams<
ParamsOrKey extends string | Record<string, string | undefined> = string
>(): Readonly<
[ParamsOrKey] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>
> {
let { matches } = React.useContext(RouteContext);
let routeMatch = matches[matches.length - 1];
Expand Down

0 comments on commit 1108f1c

Please sign in to comment.