Skip to content

Instantly share code, notes, and snippets.

@simbathesailor
Created December 25, 2019 15:59
Embed
What would you like to do?
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