0.1.0 • Published 2 years ago

solid-outside-click-handler v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

solid-outside-click-handler

npm npm version npm downloads sponsors

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