Skip to content

Commit 1108f1c

Browse files
ppbl侯宗楠
authored andcommitted
Improve the type of useParams (#8352)
Co-authored-by: 侯宗楠 <[email protected]>
1 parent 11aad9d commit 1108f1c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/react-router/index.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,10 @@ export function useOutlet(): React.ReactElement | null {
526526
*
527527
* @see https://reactrouter.com/docs/en/v6/api#useparams
528528
*/
529-
export function useParams<Key extends string = string>(): Readonly<
530-
Params<Key>
529+
export function useParams<
530+
ParamsOrKey extends string | Record<string, string | undefined> = string
531+
>(): Readonly<
532+
[ParamsOrKey] extends [string] ? Params<ParamsOrKey> : Partial<ParamsOrKey>
531533
> {
532534
let { matches } = React.useContext(RouteContext);
533535
let routeMatch = matches[matches.length - 1];

0 commit comments

Comments
 (0)