BFE.dev
buy us
a coffee
CompanyListsDiscuss
buy us
a coffee
React Coding Questions15. useClickOutside()

15. useClickOutside()

ReactHooks
Share

  - accepted / - tried

Click above header menu on this page, you can see that the dropdown menu is dismissed after clicking outside.

Now you are asked to implement a React hook to make it eaiser to implement such behavior.

function Component() {
  const ref = useClickOutside(() => {
    alert('clicked outside')
  });
  return <div ref={ref}>..</div>
}
prev

What is time & space complexity of your approach?

(9)

Try it out

Console