{"id":17717705,"url":"https://github.com/palerdot/use-async-confirm","last_synced_at":"2025-10-08T03:43:37.467Z","repository":{"id":258587762,"uuid":"875265955","full_name":"palerdot/use-async-confirm","owner":"palerdot","description":"Async, headless confirm hook (for ReactJS) that you can await on","archived":false,"fork":false,"pushed_at":"2024-11-05T05:28:13.000Z","size":484,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-01T17:36:43.517Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palerdot.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-19T14:26:23.000Z","updated_at":"2024-11-05T05:28:17.000Z","dependencies_parsed_at":"2024-10-25T17:28:47.448Z","dependency_job_id":null,"html_url":"https://github.com/palerdot/use-async-confirm","commit_stats":null,"previous_names":["palerdot/use-async-confirm"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/palerdot/use-async-confirm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palerdot%2Fuse-async-confirm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palerdot%2Fuse-async-confirm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palerdot%2Fuse-async-confirm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palerdot%2Fuse-async-confirm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palerdot","download_url":"https://codeload.github.com/palerdot/use-async-confirm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palerdot%2Fuse-async-confirm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278886409,"owners_count":26062975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-25T14:29:31.127Z","updated_at":"2025-10-08T03:43:37.436Z","avatar_url":"https://github.com/palerdot.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `use-async-confirm`\n\nAsync, headless `useConfirm` hook that you can await on.\n\n![tests](https://github.com/palerdot/use-async-confirm/actions/workflows/test.yml/badge.svg)\n\n- **Async**: returns async `confirm` that you can await on\n- **Headless**: No markup, context or provider to add. You get plain functions from hook that you can compose according to your needs. \n- **Better DX**: All the control flow stays in your event handler (e.g. onClick). You can simply await on the confirm callback and go on with your app logic\n\n`v1.x` is compatible with `React` `v18`.\n\n### Installation\n\n```shell\n# pnpm\npnpm add use-async-confirm\n\n# npm\nnpm install use-async-confirm\n```\n\n### Quick Example\n\n```javascript\n// Example usage\nimport { useConfirm } from \"use-async-confirm\"\n\nfunction MyComponent() {\n    const { confirm, onConfirm, onCancel, open, onOpenChange } = useConfirm()\n\n    const handleConfirm = async function () {\n        // control flow stays in your event handler\n        // you can just await on confirm\n        const confirmed = await confirm()\n\n        if (confirmed === true) {\n            // confirmed action\n            alert(\"User confirmed the action\")\n        } else {\n            // user cancelled the action\n            alert(\"User cancelled the action\")\n        }\n    }\n\n    return (\n        \u003cdiv\u003e\n            \u003cButton onClick={handleConfirm}\u003eDelete\u003c/Button\u003e\n            \u003cMyModal open={open} onOpenChange={onOpenChange}\u003e\n                \u003cbutton onClick={onConfirm}\u003eConfirm\u003c/button\u003e\n                \u003cbutton onClick={onCancel}\u003eCancel\u003c/button\u003e\n            \u003c/MyModal\u003e\n        \u003c/div\u003e\n    )\n}\n```\n\n### Usage\n\n#### Import `useConfirm`\n\n```javascript\nimport { useConfirm } from 'use-async-confirm'\n\n// you will get these helper functions that you can compose in your application logic\nconst { confirm, onConfirm, onCancel, open, onOpenChange } = useConfirm()\n```\n\n#### `useConfirm` returns following helper functions\n\n| function    | type            | Description                                                    |\n| ----------- |-----------------| -------------------------------------------------------------- |\n| confirm     | async function  | This is the function that you can await on. `const hasConfirmed = await confirm()`. You can compose this function in your event handler or anywhere depending on your application logic.  |\n| open        | boolean         | state indicatiing if the confirmation action in progress. You can pass this to your Modal (e.g. shadcn modal) to control opening/closing the modal |\n| onOpenChange | function: (state: boolean) =\u003e void (or) React.Dispatch\u003cReact.SetStateAction\u003cboolean\u003e\u003e | state update function.You can pass this to your modal (e.g. shadcn modal) or use this to control your modal display status |\n| onConfirm    | function       | Calling this function will resolve the confirm action with `true` / truthy value. You can call this in your confirmation button in your modal. |\n| onCancel    | function       | Calling this function will resolve the confirm action with `false` / falsy value. You can call this in your cancel button in your modal. |\n\n### About\n\nWorks well with `shadcn` or other UI libraries as it is headless and gives you complete control over how you compose the hooks. Run `pnpm dev` locally to see an example of `shadcn` integration.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalerdot%2Fuse-async-confirm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalerdot%2Fuse-async-confirm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalerdot%2Fuse-async-confirm/lists"}