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

前端 未结 3 613
悲&欢浪女
悲&欢浪女 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:06

    For React 16.8 with hooks:

    ...
    import {withRouter, RouteComponentProps} from 'react-router-dom';
    ...
    const ChildComponent: React.FunctionComponent = ({history}) => {
    ...
    }
    

提交回复
热议问题