{"id":13834136,"url":"https://github.com/doasync/use-call","last_synced_at":"2025-03-22T10:31:31.480Z","repository":{"id":34134863,"uuid":"170383375","full_name":"doasync/use-call","owner":"doasync","description":"useCall React hook","archived":false,"fork":false,"pushed_at":"2023-01-04T02:45:16.000Z","size":1388,"stargazers_count":8,"open_issues_count":13,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-20T20:37:45.627Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/doasync.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-02-12T20:06:22.000Z","updated_at":"2024-06-02T03:50:23.000Z","dependencies_parsed_at":"2023-01-15T05:01:12.254Z","dependency_job_id":null,"html_url":"https://github.com/doasync/use-call","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doasync%2Fuse-call","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doasync%2Fuse-call/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doasync%2Fuse-call/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doasync%2Fuse-call/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doasync","download_url":"https://codeload.github.com/doasync/use-call/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244943798,"owners_count":20536290,"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-08-04T13:00:55.449Z","updated_at":"2025-03-22T10:31:31.215Z","avatar_url":"https://github.com/doasync.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"# useCall React hook\n\n[![NPM Version][npm-image]][npm-url] ![NPM Downloads][downloads-image] [![GitHub issues][issues-image]][issues-url] [![Telegram][telegram-image]][telegram-url]\n\n[npm-image]: https://img.shields.io/npm/v/use-call.svg\n[npm-url]: https://www.npmjs.com/package/use-call\n[downloads-image]: https://img.shields.io/npm/dw/use-call.svg\n[issues-image]: https://img.shields.io/github/issues/doasync/use-call.svg\n[issues-url]: https://github.com/doasync/use-call/issues\n[telegram-image]: http://i.imgur.com/WANXk3d.png\n[telegram-url]: https://t.me/doasync\n\nThis package is about calling functions in React components\n\n## Installation\n\n```bash\nnpm install use-call\n```\nor\n```bash\nyarn add use-call\n```\n\n## Usage\n\n#### `useCall`\n\n```js\nimport { useCall } from 'use-call'\n```\n\nCall a function lazily with arguments and just get cached result on next renders\n\nIt takes a function and arguments: `const useCall = (fn, ...args) =\u003e`\n\n```js\nconst defaultValues = useCall(getDefaultValues)\nconst three = useCall(sum, 1, 2) // fn, ...args\nconst companyPromise = useCall(fetchCompany, { companyId: 102 }) // payload\n```\n\n#### `useAsyncCall`\n\n```js\nimport { useAsyncCall } from 'use-call'\n```\n\nCall an async function and handle promise. Returns the following array: `[result, error, pending]`\n\n```js\nconst [company] = useAsyncCall(fetchCompany, { companyId: 234 })\nconst [user, userError, userLoading] = useAsyncCall(fetchUser, 120) // id\n```\n\n## Useful packages\n\n`usePromise` hook is used to handle promises in `useAsyncCall`\n\nSee docs: https://github.com/doasync/use-promise\n\n```js\nconst [data, dataError, loading] = usePromise(fetchDataPromise)\n```\n\n---\n\nUse `once-only` package to create a function to be called once\n\nSee docs: https://github.com/doasync/once-only\n\n```js\nconst fetchUsersOnce = onceOnly(fetchUsers) // not in render\nconst usersPromise = useCall(fetchUsersOnce, 234)\n```\n\n### Tip\n\nIf you found this hook useful, please star this package on [GitHub](https://github.com/doasync/use-call) ★\n\n### Author\n@doasync\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoasync%2Fuse-call","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoasync%2Fuse-call","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoasync%2Fuse-call/lists"}