HTML 元素 props
· 阅读需 1 分钟
很多时候我们会有元素标签上显示的属性来获取元素的 props
import { HTMLAttributes } from "react"
type MyDivProps = HTMLAttributes<HTMLDivElement>
但其实,React 内置更为方便的泛型工具 ComponentProps
import { ComponentProps } from "react"
type MyDivProps = ComponentProps<"div">
HTMLAttributes<HTMLDivElement> 和 ComponentProps<"div"> 的区别在于,后者包含了 ref 和 key 属性