useClickAnyWhere
Custom hook that handles click events anywhere on the document.
Usage
tsx
import { useState } from 'react'
import { useClickAnyWhere } from 'vhooks'
export default function Component() {
const [count, setCount] = useState(0)
useClickAnyWhere(() => {
setCount(prev => prev + 1)
})
return <p>Click count: {count}</p>
}Installation
sh
pnpm dlx scaflo@latest https://raw.githubusercontent.com/programming-with-ia/vDocs/scaflos/hooks/useClickAnyWhere.json -e %src%/hookssh
npx scaflo@latest https://raw.githubusercontent.com/programming-with-ia/vDocs/scaflos/hooks/useClickAnyWhere.json -e %src%/hookssh
bunx scaflo@latest https://raw.githubusercontent.com/programming-with-ia/vDocs/scaflos/hooks/useClickAnyWhere.json -e %src%/hookssh
yarn dlx scaflo@latest https://raw.githubusercontent.com/programming-with-ia/vDocs/scaflos/hooks/useClickAnyWhere.json -e %src%/hooksAPI
▸ useClickAnyWhere(handler): void
Custom hook that handles click events anywhere on the document.
Parameters
| Name | Type | Description |
|---|---|---|
handler | (event: MouseEvent) => void | The function to be called when a click event is detected anywhere on the document. |
Returns
void
Hook
ts
import { useEventListener } from 'vhooks'
export function useClickAnyWhere(handler: (event: MouseEvent) => void) {
useEventListener('click', event => {
handler(event)
})
}