From e223e4483321ffcf5b72f5baeae5266f8947e375 Mon Sep 17 00:00:00 2001 From: Oliver Jackman Date: Fri, 20 Mar 2020 15:20:37 +0000 Subject: [PATCH] Fix @reach/router .useMatch types. Path params are added to the return object. (#43248) --- types/reach__router/index.d.ts | 3 ++- types/reach__router/reach__router-tests.tsx | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types/reach__router/index.d.ts b/types/reach__router/index.d.ts index 8cb291a5e4..07cf7ec9e0 100644 --- a/types/reach__router/index.d.ts +++ b/types/reach__router/index.d.ts @@ -4,6 +4,7 @@ // A.Mokhtar , // Awwit // wroughtec +// O.Jackman // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 @@ -161,4 +162,4 @@ export function useNavigate(): NavigateFn; export function useParams(): any; -export function useMatch(pathname: string): null | { uri: string; path: string }; +export function useMatch(pathname: string): null | { uri: string; path: string, [param: string]: string }; diff --git a/types/reach__router/reach__router-tests.tsx b/types/reach__router/reach__router-tests.tsx index ac859d18f5..53889a8865 100644 --- a/types/reach__router/reach__router-tests.tsx +++ b/types/reach__router/reach__router-tests.tsx @@ -7,7 +7,8 @@ import { LocationProvider, RouteComponentProps, Router, - Redirect + Redirect, + useMatch } from '@reach/router'; interface DashParams { @@ -22,6 +23,13 @@ const Dash = (props: RouteComponentProps) => ( const NotFound = (props: RouteComponentProps) =>
Route not found
; +const UseMatchCheck = (props: RouteComponentProps) => { + const match = useMatch('/params/:one'); + return ( +
{match ? match.one : 'NO PATH PARAM' }
+ ); +}; + render( @@ -32,6 +40,7 @@ render( +