Dim*_*imo 9 reactjs eslint react-router-v4
我正在使用React-Router v4的Match对象将params传递给下一个组件.我的路由就像:
<Switch>
<Route exact path="/" component={ExperimentListPage} />
<Route path="/experiment/:experiment" component={ExperimentResultsPage} />
</Switch>
Run Code Online (Sandbox Code Playgroud)
我的子组件看起来像:
const ExperimentResultsPage = props => (
<ExperimentResultsContainer experimentName={props.match.params.experiment} />
);
export default withRouter(ExperimentResultsPage);
Run Code Online (Sandbox Code Playgroud)
这一切都按预期工作,但是ESLint对我的使用非常不满意,match.params.experiment并且错误[eslint] 'match.params.experiment' is missing in props validation (react/prop-types)
我在React文档中看到我可以使用PropTypes.shape我的params对象,但我希望有更好的方法,特别是因为Match对象包含很多字段.
有没有更好的方法将Match路径对象添加到道具验证?那会是什么样子?如果没有,我是否错过了其他可以帮助解决此问题的方法?
我碰到了类似的东西,eslint似乎很好,只是声明我使用道具并忽略匹配中未使用的字段:
match: PropTypes.shape({
params: PropTypes.shape({
experiment: PropTypes.string,
}),
}).isRequired,
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1634 次 |
| 最近记录: |