泛型在react组件中的使用
来源:2-12 泛型(Generics) 第三部分 - 类和接口

进阶的前端小白
2020-03-27
export const Button: FC<ButtonProps> = (props) => {},这种属于泛型的哪种应用呢,不是使用的过程中知道类型,那为什么要先定义一个ButtonProps类型呢
写回答
1回答
-
同学你好 这个属于 泛型 和 function 一起使用,定义 ButtonProps 类型以后,在函数体中的 props 可以自动获得
type PropsWithChildren<P> = P & { children?: ReactNode };
这种类型,它可以帮助自动补全 ButtonProps的所有属性,同时也可获得 children 属性
012020-03-29
相似问题