Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I find types for react-router-dom Location, History and Match?

When I use withRouter from react-router-dom v4.3.2, it passes three props to the component, history, match and location. Where can I find the type definition for these three objects for TypeScript?

I have checked this link https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-router/v3/lib but it doesn't have version 4. In addition, the type defined there doesn't include History location and match.

like image 277
Joey Yi Zhao Avatar asked Jun 05 '19 06:06

Joey Yi Zhao


People also ask

Where is the history location in react?

You can use useHistory , useLocation and useRouteMatch in your component to get match , history and location . You can use withRouter HOC in order to inject match , history and location in your component props. You can use withRouter HOC in order to inject router , params , location , routes in your component props.

What are the types of components in react router?

There are three primary categories of components in React Router: routers, like <BrowserRouter> and <HashRouter> route matchers, like <Route> and <Switch> and navigation, like <Link> , <NavLink> , and <Redirect>


1 Answers

import { History, Location } from 'history';
import {match} from 'react-router';

You can check out @types/react-router. There you can see all the types defined and imported from @types/history.

like image 89
Siraj Alam Avatar answered Nov 15 '22 08:11

Siraj Alam