solid-outside-click-handler
v0.1.0
Published
Detect and handle clicks outside a Solid component.
Downloads
76
Maintainers
Readme
solid-outside-click-handler
Detect and handle clicks outside a Solid component.
Usage
Installation
npm install solid-outside-click-handler --save
yarn add solid-outside-click-handler ## or in yarn
Example
Using the HOC
import { Component } from 'solid-js'
import { OutsideClickHandler } from 'solid-outside-click-handler'
const Page: Component = () => (
<OutsideClickHandler
onOutsideClick={ () => console.log('Outside!') }
>
<div>Hello ✨</div>
</OutsideClickHandler>
)
Using the hook
import { Component, onMount } from 'solid-js'
import { useOutsideClickHandler } from 'solid-outside-click-handler'
const Page: Component = () => {
let ref
onMount(() => {
useOutsideClickHandler(ref, () => console.log('Outside!'))
})
return (
<div ref={ ref }>Hello ✨</div>
)
}
License
MIT