只允许在React组件中使用特定类型的子代

只允许在React组件中使用特定类型的子代,第1张

只允许在React组件中使用特定类型子代

您可以为每个孩子使用displayName,可通过以下类型进行访问:

for (child in this.props.children){  if (this.props.children[child].type.displayName != 'Card'){    console.log("Warning CardGroup has children that aren't Card components");  }  }


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5622532.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存