What is the most intelligent way to close the Dropdown Menu on clicking outside of its scope?

I have created this simple Dropdown in React and everything works fine until I click outside the scope of the Dropdown.
https://codesandbox.io/s/restless-fast-x2jhe8

I’ve added a min-height: 100vh property on the body, to replicate a full size page. Like I said, the functionality to close the Dropdown menu when we click anywhere in the page that is not the Dropdown, is not implemented yet. I am not sure how to handle this in the most elegant way. I tried something along the lines of adding an event listener on the body with useEffect and then checking if event.target has class dropdown, but it didn’t perform as expected.