我想使用元素子元素的道具并希望验证这些道具。
有可能实现这一点吗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,
.
.
.
}
暮色呼如
相关分类