react ref typescript type code example
Example 1: Cannot find name 'RefObject'
class TestApp extends React.Component<AppProps, AppState> {
private stepInput: React.RefObject<HTMLInputElement>;
constructor(props) {
super(props);
this.stepInput = React.createRef();
}
render() {
return <input type="text" ref={this.stepInput} />;
}
}
Example 2: react forwardref typescript
type MyProps = {
name: string;
}
const CustomInput = forwardRef<HTMLInputElement, MyProps>(props) => {
// access your props and ref here
}