Last active
April 9, 2020 09:01
-
-
Save treyhuffine/d4c62f540a45d7d07231cb9cb81d7456 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function FancyInput(props, ref) { | |
const inputRef = useRef(); | |
useImperativeHandle(ref, () => ({ | |
focus: () => { | |
inputRef.current.focus(); | |
} | |
})); | |
return <input ref={inputRef} ... />; | |
} | |
FancyInput = React.forwardRef(FancyInput); | |
// You can now get a ref directly to the DOM button: | |
const fancyInputRef = React.createRef(); | |
<FancyInput ref={fancyInputRef}>Click me!</FancyInput>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function FancyInput(props, ref) {
It is not typescript code. Props and ref should not tot be any.
Use should use
And you will get type error