react-router-dom with TypeScript

前端 未结 7 669
清歌不尽
清歌不尽 2021-01-30 19:56

I\'m trying to use react router with TypeScript. However, I have certain problems using withRouter function. On the last line, I\'m getting pretty weird error:

A         


        
7条回答
  •  灰色年华
    2021-01-30 20:59

    After browsing the typescript definitions I discovered the RouteComponentProps interface so I now model my containers like so

    type RouteParams = {
        teamId: string; // must be type string since route params
    }
    
    interface Props extends RouteComponentProps, React.Props { }
    
    type State = {
        players: Array;
    }
    
    export class PlayersContainer extends React.Component{} 
    

    now in the component class the route props can be accessed like this: let teamid = this.props.match.params.teamId;

提交回复
热议问题