是否可以从React Node中分辨出渲染prop appart?
我正在制作一个可重复使用的组件,该组件当前接受反应节点。但是,我也想让它接受渲染道具功能。但是,我认为仅检查typeof propName ===“函数”
以区分这两个选项是不起作用的,因为React Node可能是功能组件。因此,我的问题是在功能组件上是否有一个属性,可以让我从常规功能告诉他们appart。
I am making a reusable component that currently accepts a ReactNode. However I would also like to have it accept a render prop function. However I think just checking if typeof propName === "function"
to distinguish the two options would not work since a ReactNode might be a functional component. So my question is whether there is a property defined on functional components that would allow me to tell them appart from a regular function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对反应节点感到困惑。查看定义实际上从来都不是一个函数。因此,
typeof propname ===“函数”
应该有效。I was confused about the ReactNode. Looking at the definition it's actually never a function. So
typeof propName === "function"
should work.