【发布时间】:2020-11-06 20:24:10
【问题描述】:
我想使用一个元素的子元素的道具并想要验证这些道具。
是否可以通过prop-types 实现这一点?
export default function MyComponent(props) {
return (
<div>
{React.Children.map(props.children, (c, i) => {
// Want to do something with validated c.props.somePropThatNeedValidation (if exists of course)
// c Is not an element that I wrote so I can't validate it there
{React.cloneElement(c, {extras})}
}
)}
</div>
)
}
MyComponent.propTypes = {
children: PropTypes.node,
.
.
.
}
【问题讨论】:
标签: javascript reactjs dictionary children react-proptypes