{"id":21075161,"url":"https://github.com/nutgaard/use-async","last_synced_at":"2025-03-14T03:40:48.378Z","repository":{"id":35026793,"uuid":"198045383","full_name":"nutgaard/use-async","owner":"nutgaard","description":"useAsync hook for use with react","archived":false,"fork":false,"pushed_at":"2023-01-06T01:31:35.000Z","size":2692,"stargazers_count":0,"open_issues_count":23,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-25T07:18:14.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/nutgaard.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}},"created_at":"2019-07-21T10:57:15.000Z","updated_at":"2020-01-27T21:45:25.000Z","dependencies_parsed_at":"2023-01-15T12:18:08.682Z","dependency_job_id":null,"html_url":"https://github.com/nutgaard/use-async","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nutgaard%2Fuse-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nutgaard%2Fuse-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nutgaard%2Fuse-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nutgaard%2Fuse-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nutgaard","download_url":"https://codeload.github.com/nutgaard/use-async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243521141,"owners_count":20304183,"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":[],"created_at":"2024-11-19T19:19:57.952Z","updated_at":"2025-03-14T03:40:48.350Z","avatar_url":"https://github.com/nutgaard.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-async\n\n[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)\n[![Travis](https://img.shields.io/travis/nutgaard/use-async.svg)](https://travis-ci.org/nutgaard/use-async)\n[![codecov](https://codecov.io/gh/nutgaard/use-async/branch/master/graph/badge.svg)](https://codecov.io/gh/nutgaard/use-async)\n[![dependencies Status](https://david-dm.org/nutgaard/use-async/status.svg)](https://david-dm.org/nutgaard/use-async)\n\n### Installation\n\n```\nnpm install @nutgaard/use-async --save\n```\n\n### Usage\nThe library exposes one hook `useAsync`, and three utility-functions to help use the result (`isPending`, `hasData` and `hasError`).\n\n```typescript\nimport React from 'react';\nimport useAsync, { isPending, hasError } from '@nutgaard/use-async';\n\nconst source = React.useCallback((isRerun) =\u003e Promise.resolve(\"your data here\"), []);\nconst result = useAsync(source);\n\nif (isPending(result)) {\n  return \u003cSpinner /\u003e;\n} else if (hasError(result)) {\n  return \u003cError /\u003e\n} \n\nreturn \u003cpre\u003e{result.data}\u003c/pre\u003e\n``` \n\n### useAsync API\n\n| Argument  | Type | Optional | Default |\n| ------------- | ------------- | ------------- | ------------- |\n| `source`  | `(isRerun) =\u003e Promise\u003cDATA\u003e` | No | - |\n| `lazy`  | `boolean`  | Yes | `false` |\n| `dependencyList`  | `Array\u003cany\u003e`  | Yes | `undefiend` |\n\nIn cases where `dependencyList` is defined it is passed on to `useEffect` instead of `source`.  \nThis allows a greater control of when the effect should run in cases where the `source` does\nnot necessarily change.\n\n#### Types\nFull documentation of types can be seen [here](https://www.utgaard.xyz/use-async/), or in the 80-ish lines of code.\n\n## Credits\n\nMade using the awesome [typescript library starter](https://github.com/alexjoverm/typescript-library-starter) \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnutgaard%2Fuse-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnutgaard%2Fuse-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnutgaard%2Fuse-async/lists"}