useClickAnyWhere


This simple React hook offers you a click event listener at the page level, don't repeat yourself.

It is made on the useEventListener.

Usage

import { useState } from 'react'

import { useClickAnyWhere } from 'reactchemy'

export default function Component() {
   const [count, setCount] = useState(0)

   useClickAnyWhere(() => {
      setCount(prev => prev + 1)
   })

   return <p>Click count: {count}</p>
}

Hook

import { useEventListener } from 'reactchemy'

type Handler = (event: MouseEvent) => void

export function useClickAnyWhere(handler: Handler) {
   useEventListener('click', (event) => {
      handler(event)
   })
}