A SolidJS hook to detect clicks outside of an element
Install it:
npm i solid-click-outside # or yarn add solid-click-outside # or pnpm add solid-click-outsideUse it:
import useClickOutside from 'solid-click-outside' const App = () => { const [target, setTarget] = createSignal<HTMLElement | undefined>(); useClickOutside(target, () => { console.log('clicked outside') }) return ( <div ref={setTarget}> Click outside this box. Open console to see the message. </div> ) }