Skip to main content

useClickAnywhere()

The useClickAnywhere hook detects clicks anywhere on the document and triggers a callback function when a click event occurs, making it useful for tracking user interactions across the entire page.

Import

import { useClickAnywhere } from "reactuals";

Demo

Click anywhere

Loading...

Usage

import { useClickAnywhere } from "reactuals";
import React from "react";

export const Component = () => {
const [count, setCount] = React.useState(0);

useClickAnywhere(() => {
setCount((prevCount) => prevCount + 1);
});

return (
<div>
<p>Click Count: {count}</p>
</div>
);
};