trevorsg,您需要传递按钮属性:
import * as React from 'react'type ButtonProps = React.HTMLProps<HTMLButtonElement>const FancyButton = React.forwardRef<HTMLButtonElement, ButtonProps>((props, ref) => ( <button type="button" ref={ref} className="FancyButton"> {props.children} </button>))// You can now get a ref directly to the DOM button:const ref = React.createRef<HTMLButtonElement>()<FancyButton ref={ref}>Click me!</FancyButton>添加:
在最新版本的TS和@ types /
react中,您也可以使用
React.ComponentPropsWithoutRef<'button'>代替
React.HTMLProps<HTMLButtonElement>



