Typescript: How to add type check for history object in React?

前端 未结 3 612
悲&欢浪女
悲&欢浪女 2021-02-01 12:22

I have the following piece of code, which receives a history object as prop:

const ChildComponent = ({ history }) => (
        
3条回答
  •  一生所求
    2021-02-01 13:16

    The simplest solution I found

    import { RouteComponentProps } from 'react-router-dom';
    
    ....
    
    interface Foo {
       location: RouteComponentProps.location;
       history: RouteComponentProps.history;
       match: RouteComponentProps.match;
    }
    

提交回复
热议问题