useClickAway
Installation
npx sse-hooks add use-click-away
yarn dlx sse-hooks add use-click-away
pnpm dlx sse-hooks add use-click-away
deno run -A npm:sse-hooks add use-click-away
bunx sse-hooks add use-click-away
Usage
import { useClickAway } from "./{hooks file}";
const handleClickAway = () => {
console.log("Clicked outside!");
setOpen(false);
};
const { ref, listenerProps } = useClickAway(handleClickAway);
return (
<div ref={ref} {...listenerProps}>
I will detect clicks outside of me.
</div>
);
API
Parameters
| Prop | Default | Type |
|---|---|---|
options |
|
Configuration options for the hook.
|
onClickAway | - |
The callback function to be called when a click outside is detected. |
Returns
| Return Value | Default | Type |
|---|---|---|
listenerProps | - |
|
ref | - |
|
Types Aliases
Changelog
useClickAnyWhere
Custom hook that handles click events anywhere on the document.
useAutoSave
A robust hook for auto-saving form data with debouncing, race-condition handling, and lifecycle safety. It monitors the `data` state and triggers the `onSave` callback after a specified `delay` of inactivity. It also provides a smart `onChange` handler that adapts to both React Events and direct values.