简体   繁体   中英

React PropType element of type

From the official ReactJS docs page we can use React.PropTypes.element to validate a single child.

With React.PropTypes.element you can specify that only a single child can be passed to a component as children.

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? It sounds like that might be what you are looking for: https://facebook.github.io/react/docs/reusable-components.html#prop-validation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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