Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Created February 13, 2019 05:48
Show Gist options
  • Select an option

  • Save jrwebdev/0b7ba1f0bd0da2dcdecdd1112c0f2787 to your computer and use it in GitHub Desktop.

Select an option

Save jrwebdev/0b7ba1f0bd0da2dcdecdd1112c0f2787 to your computer and use it in GitHub Desktop.

Revisions

  1. jrwebdev created this gist Feb 13, 2019.
    13 changes: 13 additions & 0 deletions useImperativeHandle-usage.tsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    import MyInput, { MyInputHandles } from './MyInput';

    const Autofocus = () => {
    const myInputRef = useRef<MyInputHandles>(null);

    useEffect(() => {
    if (myInputRef.current) {
    myInputRef.current.focus();
    }
    });

    return <MyInput ref={myInputRef} />
    }