DEV Community

Discussion on: Click outside listener for React components in 10 lines of code [Using Hooks]

Collapse
 
vibhanshu909 profile image
vibhanshu pandey

well, you must track your component's state, either its a dialog box, a context menu or any other component, the onClose method is called when the user clicks outside of your reffered component, it's upto you wheather you want to change state or call an API or do something else.