ComponentType和Component
来源:4-9 【高阶组件HOC】withAddToCart()

Boy越越
2021-06-10
老师的代码中const withAddToCart = (ChildComponent:React.ComponentType)=>{}
请问可以写成const withAddToCart = (ChildComponent:React.Component)=>{} 吗?
React.Component和React.ComponentType区别是什么?
写回答
1回答
-
阿莱克斯刘
2021-06-11
有两篇文章我们可以参考一下:
1. 第一篇:https://flow.org/en/docs/react/types/
文章的这个部分会告诉我们componentType是用于修饰HOC的。
2. 第二篇文章:
https://medium.com/@jrwebdev/react-higher-order-component-patterns-in-typescript-42278f7590fb
图片中的段落告诉我们componentType是FC和class Compnonet的集合
如果打开源码,我们也可以得到印证:
30
相似问题