15. useClickOutside()
分享给更多人
-通过 / -执行
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>}
Try it out
Console