Hooks
useConfirm
A hook that shows a confirmation dialog and returns a promise that resolves when the user accepts or rejects. Perfect for delete or irreversible actions.
Installation
pnpm dlx shadcn@latest add https://rafay.sh/r/use-confirm.json
Usage
1import { useConfirm } from "@/hooks/use-confirm.tsx";1const [DeleteDialog, confirm] = useConfirm(
2 "Are you sure?",
3 "This will delete all the files from this project?",
4 "destructive"
5);
6
7const handleDoSomething = async () => {
8 const ok = await confirm();
9 if (!ok) return;
10
11 // Do something
12};
13
14<div>
15 <DeleteDialog />
16</div>note: i am not the creator of this hook. i found this from an article but i don't remember the name of the author. if you know them, reach out to me so i can give credits.