对于使用React和类型记录,React.ComponentPropsWithoutRef
是用来做什么的。有关于这个财产的文件吗?
发布于 2022-07-20 11:34:27
ComponentPropsWithoutRef类型可用于获取HTML元素的所有本机属性,作为组件的支持类型。
您可以简单地创建一个类型,它将所有本机按钮属性作为道具,如下所示:
type ButtonProps = React.ComponentPropsWithoutRef<"button">
const Button = ({ children, onClick, type }: ButtonProps) => {
return (
<button onClick={onClick} type={type}>
{children}
</button>
)
}
这里有一个链接,它更多地讨论在打字本中使用ComponentPropsWithoutRef的情况。请参阅“如何键入(扩展) HTML元素”和"ComponentPropsWithoutRef vs ElementHTMLAttributes“部分
https://stackoverflow.com/questions/73049726
复制相似问题