Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Cogentx/81112f864522db5b880b67c8c9996b26 to your computer and use it in GitHub Desktop.
Save Cogentx/81112f864522db5b880b67c8c9996b26 to your computer and use it in GitHub Desktop.
React TypeScript useRef Type Definitions
// It's important to pass NULL as the default value to useRef Hook since React.useRef can only be NULL or an Element Object.
// <div> reference type
const divRef = React.useRef<HTMLDivElement>(null);
// <button> reference type
const buttonRef = React.useRef<HTMLButtonElement>(null);
// <br /> reference type
const brRef = React.useRef<HTMLBRElement>(null);
// <a> reference type
const linkRef = React.useRef<HTMLLinkElement>(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment