【发布时间】:2020-03-28 07:37:56
【问题描述】:
我想定义某个无状态组件的location.state 可以是什么类型。
我找到了几篇基于RouteComponentProps 类型的文章,但我无法弄清楚细节。
假设在这个例子中,我希望 location.state 属性是类型
type StateType = {
id: number,
type: number
}
或者让 type` 甚至是一个枚举。这可以实现吗?
import React from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
const Index = ({ location, history }) => {
return (
<div>Test</div>
)
}
export default withRouter(Index)
【问题讨论】:
标签: reactjs typescript react-router-dom