@rajatkapoor
👨💻Engineering Lead @ Hashnode | Indiehacker | 🌏 Remote Work Advocate
Nothing here yet.
Nothing here yet.
Hey! Thank you for reading. Having that ref in the useState dependencies ensure that things work when the element on which the ref is placed, unmounts and mounts. Imagine a case where clicking on a button shows a sidebar and we want to close the sidebar when the user clicks outside of the sidebar(and not the button). In this case the ref would be undefined as first, but would change later. And we would want to register the onOutsideClick again, passing in the new ref. Let me know if that doesn't make sense