gpt4 book ai didi

javascript - 类型的 React PropType 元素

转载 作者:行者123 更新时间:2023-11-29 15:27:03 25 4
gpt4 key购买 nike

来自official ReactJS 文档页面我们可以使用 React.PropTypes.element 来验证单个 child 。

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

问题

是否有类似的东西也可以验证子类型?

期待

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

最佳答案

您是否考虑过创建自定义 propType 验证方法?听起来这可能就是您要找的:https://facebook.github.io/react/docs/reusable-components.html#prop-validation

关于javascript - 类型的 React PropType 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38020492/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com