Skip to content

Instantly share code, notes, and snippets.

@schabluk
Created February 6, 2019 18:58
Show Gist options
  • Save schabluk/47ffecd16ec7411fa2d764ddd9228677 to your computer and use it in GitHub Desktop.
Save schabluk/47ffecd16ec7411fa2d764ddd9228677 to your computer and use it in GitHub Desktop.
useRef on HTML element with TypeScript
function DraftEditor({ metaData, readOnly = false, decorators = [] }: IDraftEditor) {
const editorRef = useRef<HTMLDivElement>(null)
const handleFocusClick = () => {
const { current: editor } = editorRef
if (editor) { editor.focus() }
}
return (
<div ref={editorRef} onClick={handleFocusClick} />
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment