useClickInside
Custom React hook that triggers a callback function when a click event occurs inside a specified DOM element.
Overview
This custom hook sets up an event listener for clicks on the document and checks if the click occurred inside the referenced element.
If the click is inside, it calls the provided callback function fn
.
The effect properly cleans up by removing the event listener when the component unmounts or the dependencies change.
Code
API
Parameters
ref - A React ref object pointing to the target DOM element. fn - A callback function to be executed when a click event is detected inside the element.