小编典典

如何检测React组件与React元素?

reactjs

React.isValidElement对React组件和React元素均测试为true。我将如何具体测试对象是React组件?目前,我正在通过测试进行操作typeof obj.type === 'function',但我希望有更好的方法。


阅读 314

收藏
2020-07-22

共1个答案

小编典典

ReactComponent.prototype.isReactComponent = {};

/node_modules/react/lib/ReactComponent.js中的33

使用npm安装。在这一点上,没有直接的方法可用来检查其有效性。你在做什么是正确的。

2020-07-22