问题描述
目前需求做一个HOC组件调试工具,选中一个被HOC包裹的组件,会有一个选中的框,同时一个浮层提示组件数据,如果有propTypes,做出一些相应警告和提示。
开发过程中,发现取到propTypes都是func。
相关代码
const HOC = (Ele) => class extends Component{
render() {
console.log(Ele.propTypes)
return <Ele {...this.props} />
}
}
事实上它本来就是一个function
假设你使用了propTypes模块,
我们以propTypes.string为例, 可以看源码:
https://github.com/aackerman/...
这个函数真正起到作用是时候是组件接受prop的时候,将组件接受的prop作为参数传给这个函数。
https://github.com/facebook/r...