React to clicks outside an element

const myCallback = useCallback(() => console.log('clicked outside'), [])
const ref = useOutsideClickListener(myCallback)