{"id":47836362,"url":"https://github.com/shahradelahi/react-hook-action","last_synced_at":"2026-04-03T20:32:35.340Z","repository":{"id":340074665,"uuid":"989418052","full_name":"shahradelahi/react-hook-action","owner":"shahradelahi","description":"⚡️ Lightweight \u0026 type-safe React hook for managing async actions.","archived":false,"fork":false,"pushed_at":"2026-03-17T23:45:04.000Z","size":131,"stargazers_count":3,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-25T18:11:02.787Z","etag":null,"topics":["async-actions","error-handling","hooks","loading-state","react","state-management","type-safe","typescript","zustand"],"latest_commit_sha":null,"homepage":"https://npmjs.com/react-hook-action","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/shahradelahi.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-24T04:05:15.000Z","updated_at":"2026-02-24T16:22:42.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/shahradelahi/react-hook-action","commit_stats":null,"previous_names":["shahradelahi/react-hook-action"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/shahradelahi/react-hook-action","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Freact-hook-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Freact-hook-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Freact-hook-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Freact-hook-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shahradelahi","download_url":"https://codeload.github.com/shahradelahi/react-hook-action/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shahradelahi%2Freact-hook-action/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31375769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T17:53:18.093Z","status":"ssl_error","status_checked_at":"2026-04-03T17:53:17.617Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["async-actions","error-handling","hooks","loading-state","react","state-management","type-safe","typescript","zustand"],"created_at":"2026-04-03T20:32:35.243Z","updated_at":"2026-04-03T20:32:35.320Z","avatar_url":"https://github.com/shahradelahi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  \u003csup\u003ereact-hook-action\u003c/sup\u003e\n  \u003cbr\u003e\n  \u003ca href=\"https://github.com/shahradelahi/react-hook-action/actions/workflows/ci.yml\"\u003e\u003cimg src=\"https://github.com/shahradelahi/react-hook-action/actions/workflows/ci.yml/badge.svg?branch=main\u0026event=push\" alt=\"CI\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/react-hook-action\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/react-hook-action.svg\" alt=\"NPM Version\"\u003e\u003c/a\u003e\n  \u003ca href=\"/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg?style=flat\" alt=\"MIT License\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://bundlephobia.com/package/react-hook-action\"\u003e\u003cimg src=\"https://img.shields.io/bundlephobia/minzip/react-hook-action\" alt=\"npm bundle size\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://packagephobia.com/result?p=react-hook-action\"\u003e\u003cimg src=\"https://packagephobia.com/badge?p=react-hook-action\" alt=\"Install Size\"\u003e\u003c/a\u003e\n\u003c/h1\u003e\n\n_react-hook-action_ is a lightweight React hook for managing asynchronous actions and their loading states, safely resolving promises and globally persisting states using Zustand.\n\n---\n\n- [Installation](#-installation)\n- [Usage](#-usage)\n- [Documentation](#-documentation)\n- [Contributing](#-contributing)\n- [License](#license)\n\n## 📦 Installation\n\n```bash\nnpm install react-hook-action\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eInstall using your favorite package manager\u003c/summary\u003e\n\n**pnpm**\n\n```bash\npnpm install react-hook-action\n```\n\n**yarn**\n\n```bash\nyarn add react-hook-action\n```\n\n\u003c/details\u003e\n\n## 📖 Usage\n\n### Basic Usage\n\nWrap any asynchronous function to automatically manage `isLoading`, `result`, and `error` states.\n\n```tsx\nimport { useAction } from 'react-hook-action';\n\nexport default function Page() {\n  const { result, error, isLoading, dispatch, reset } = useAction(\n    'fetchUser',\n    async (id: number) =\u003e {\n      const response = await fetch(`https://api.example.com/users/${id}`);\n      if (!response.ok) throw new Error('Failed to fetch user');\n      return response.json();\n    }\n  );\n\n  if (isLoading) {\n    return \u003cdiv\u003eLoading...\u003c/div\u003e;\n  }\n\n  if (error) {\n    return \u003cdiv\u003eError: {error.message}\u003c/div\u003e;\n  }\n\n  return (\n    \u003cdiv\u003e\n      {result \u0026\u0026 \u003cdiv\u003eUser: {result.name}\u003c/div\u003e}\n      \u003cbutton onClick={() =\u003e dispatch(1)}\u003eFetch User\u003c/button\u003e\n      \u003cbutton onClick={reset}\u003eReset\u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n### Initial Result\n\nYou can provide an initial result to bypass loading states when data is already available.\n\n```ts\nconst { result, dispatch } = useAction('fetchSettings', fetchSettingsFn, {\n  initialResult: { theme: 'dark', notifications: true },\n});\n```\n\n### Ignoring Errors\n\nIf you want to silently fail and ignore any errors thrown by the action, use `ignoreErrors`. This will prevent the `error` state from being updated.\n\n```ts\nconst { dispatch } = useAction('analyticsPing', sendAnalytics, {\n  ignoreErrors: true,\n});\n```\n\n### Error Callbacks\n\nEasily handle side-effects cleanly with the `onError` callback when an action fails.\n\n```ts\nconst { dispatch } = useAction('saveData', saveDataFn, {\n  onError: (error) =\u003e {\n    toast.error(`Save failed: ${error.message}`);\n  },\n});\n```\n\n## 📚 Documentation\n\nFor all configuration options, please see [the API docs](https://www.jsdocs.io/package/react-hook-action).\n\n## 🤝 Contributing\n\nWant to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/react-hook-action).\n\nThanks again for your support, it is much appreciated! 🙏\n\n## License\n\n[MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/react-hook-action/graphs/contributors).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Freact-hook-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshahradelahi%2Freact-hook-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshahradelahi%2Freact-hook-action/lists"}