useClickAnywhere

Phillmont MuktarAI Engineer
Languages

Implement a useClickAnywhere hook that handles click events anywhere in the browser window.

export default function Component() {
const [count, setCount] = useState(0);
useClickAnywhere(() => {
setCount((prev) => prev + 1);
});
return <p>Click count: {count}</p>;
}

Arguments

  • handler: (event: MouseEvent) => void: The function to be called when a click event is detected anywhere in the window

Returns

Nothing.

Loading editor