Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Created December 25, 2019 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simbathesailor/31602de84f48f0cb80ca4e23bf87eb86 to your computer and use it in GitHub Desktop.
Save simbathesailor/31602de84f48f0cb80ca4e23bf87eb86 to your computer and use it in GitHub Desktop.
blog11.md
function useCallbackRef() {
  const [domElem, setDomElem] = React.useState(null);
  function setElem(elem) {
    if (elem) {
      setDomElem(elem);
      setDomElem.current = elem; // This is important , because might be some other component which will be needing
      // access to the elem
    }
  }
  return [domElem, setElem];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment