简体   繁体   English

React PropType元素的类型

[英]React PropType element of type

From the official ReactJS docs page we can use React.PropTypes.element to validate a single child. 官方的 ReactJS文档页面,我们可以使用React.PropTypes.element来验证单个子项。

With React.PropTypes.element you can specify that only a single child can be passed to a component as children. 使用React.PropTypes.element,您可以指定只有一个子项可以作为子项传递给组件。

Question

Is there something like that which also validates the child type? 是否有类似的东西也验证了儿童类型?

Expectation 期望

React.PropTypes.elementOfType('svg').isRequired

Have you looked into creating a custom propType validation method? 您是否考虑过创建自定义propType验证方法? It sounds like that might be what you are looking for: https://facebook.github.io/react/docs/reusable-components.html#prop-validation 听起来这可能是你正在寻找的: https//facebook.github.io/react/docs/reusable-components.html#prop-validation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM