{"id":20221063,"url":"https://github.com/christoph-jerolimov/usepromises","last_synced_at":"2026-01-07T12:32:27.514Z","repository":{"id":39697728,"uuid":"246165192","full_name":"christoph-jerolimov/usepromises","owner":"christoph-jerolimov","description":"React and React Native hook to consume a Promise (similar to useEffect) with full TypeScript support","archived":false,"fork":false,"pushed_at":"2024-07-23T12:41:35.000Z","size":1018,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T14:15:50.466Z","etag":null,"topics":["react","react-hooks","react-native","reactjs","reactnative","typescript"],"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/christoph-jerolimov.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-03-09T23:40:59.000Z","updated_at":"2024-06-18T12:08:39.000Z","dependencies_parsed_at":"2024-11-14T06:51:16.477Z","dependency_job_id":null,"html_url":"https://github.com/christoph-jerolimov/usepromises","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christoph-jerolimov%2Fusepromises","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christoph-jerolimov%2Fusepromises/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christoph-jerolimov%2Fusepromises/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christoph-jerolimov%2Fusepromises/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christoph-jerolimov","download_url":"https://codeload.github.com/christoph-jerolimov/usepromises/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246093099,"owners_count":20722395,"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","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":["react","react-hooks","react-native","reactjs","reactnative","typescript"],"created_at":"2024-11-14T06:51:10.328Z","updated_at":"2026-01-07T12:32:22.492Z","avatar_url":"https://github.com/christoph-jerolimov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# usePromises\n\n**React and React Native hook to consume a Promise (similar to useEffect) with full TypeScript support**\n\n## Installation\n\n```\nnpm install --save usepromises\n```\n\nor\n\n```\nyarn add usepromises\n```\n\n## Usage / Examples\n\n### usePromise\n\n```javascript\nimport { usePromise } from 'usepromises';\n\n...\n\ninterface SampleResponse {\n  slideshow: {\n    title: string\n  }\n}\n\nfunction Example() {\n  const response = usePromise\u003cSampleResponse\u003e(async () =\u003e {\n    const response = await fetch('https://httpbin.org/json');\n    return response.json();\n  }, []);\n\n  return (\n    \u003cdiv\u003e\n      {response.isResolved \u0026\u0026 response.value.slideshow.title}\n\n      {response.isRejected ? `Error: ${response.error}` : null}\n    \u003c/div\u003e\n  );\n};\n```\n\n### useMountPromise\n\n```javascript\nimport { useMountPromise } from 'usepromises';\n\n...\n\ninterface SampleData {\n  slideshow: {\n    title: string\n  }\n}\n\nfunction Example() {\n  const [data, setData] = useState\u003cSampleData\u003e();\n  useMountPromise(async () =\u003e {\n    const response = await fetch('https://httpbin.org/json');\n    setData(await response.json());\n  });\n\n  ...\n};\n```\n\n### useUnmountPromise\n\n```javascript\nimport { useUnmountPromise } from 'usepromises';\n\n...\n\ninterface SampleResponse {\n  slideshow: {\n    title: string\n  }\n}\n\nfunction Example() {\n  useUnmountPromise(async () =\u003e {\n    const response = await fetch('https://httpbin.org/json');\n    console.warn('Server status code:', response.status);\n  });\n\n  ...\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristoph-jerolimov%2Fusepromises","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristoph-jerolimov%2Fusepromises","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristoph-jerolimov%2Fusepromises/lists"}