Skip to content

Instantly share code, notes, and snippets.

View Leejjon's full-sized avatar

Leon Liefting Leejjon

View GitHub Profile
import MyInput, { MyInputHandles } from './MyInput';
const Autofocus = () => {
const myInputRef = useRef<MyInputHandles>(null);
useEffect(() => {
if (myInputRef.current) {
myInputRef.current.focus();
}
});
export interface MyInputHandles {
focus(): void;
}
const MyInput: RefForwardingComponent<MyInputHandles, MyInputProps> = (
props,
ref
) => {
const inputRef = useRef<HTMLInputElement>(null);