{"id":13450268,"url":"https://github.com/react-rekindle/use-request","last_synced_at":"2026-01-12T06:35:37.557Z","repository":{"id":44078395,"uuid":"204895677","full_name":"react-rekindle/use-request","owner":"react-rekindle","description":"🤖React hook for making request.","archived":false,"fork":false,"pushed_at":"2023-01-07T09:08:45.000Z","size":1893,"stargazers_count":21,"open_issues_count":32,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-28T17:39:11.616Z","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/react-rekindle.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-08-28T09:28:24.000Z","updated_at":"2023-11-22T12:12:39.000Z","dependencies_parsed_at":"2023-02-06T18:16:20.914Z","dependency_job_id":null,"html_url":"https://github.com/react-rekindle/use-request","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-rekindle%2Fuse-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-rekindle%2Fuse-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-rekindle%2Fuse-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-rekindle%2Fuse-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/react-rekindle","download_url":"https://codeload.github.com/react-rekindle/use-request/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245130722,"owners_count":20565700,"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-07-31T07:00:33.066Z","updated_at":"2026-01-12T06:35:37.514Z","avatar_url":"https://github.com/react-rekindle.png","language":"TypeScript","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"# use-request\n\n\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@rekindle/use-request\" target=\"\\_parent\"\u003e\n\u003cimg alt=\"\" src=\"https://img.shields.io/npm/dm/@rekindle/use-request.svg\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@rekindle/use-request\" target=\"\\_parent\"\u003e\n\u003cimg alt=\"\" src=\"https://img.shields.io/npm/v/@rekindle/use-request.svg\" /\u003e\n\u003c/a\u003e\n\nA Tiny Custom React hooks for making request.\n\n## Feature\n\n- 👕 Typescript support.\n- 🗜️ 1.3kb after minified without gzip.\n- 📤 Easy to use with different request client.\n\n## Install\n\n```bash\nyarn add @rekindle/use-request\n```\n\n## Basic Usage\n\n```jsx\nimport useRequest from '@rekindle/use-request'\nimport getFooApi from '@/utils/axios'\n\nfunction App () {\n  const [{ loading, error, data }, fetch] = useRequest(getFooApi)\n\n  useEffect(() =\u003e { fetch() }, [fetch])\n\n  if (loading) return 'loading'\n  if (error) return 'error'\n\n  return data \u0026\u0026 \u003cdiv\u003e{data}\u003c/div\u003e\n}\n```\n\n## More Example\n\n\u003e Queries are typically start with loading, we can create a `useQuery` function before we use.\n\n```js\nfunction useQuery (api) {\n  return useRequest(api, { loading: true })\n}\n```\n\n### Query\n\n```jsx\nfunction Query () {\n  const [{ loading, error, data }, fetch] = useQuery(queryFooApi)\n\n  useEffect(() =\u003e { fetch() }, [fetch])\n\n  if (loading) return 'loading...'\n  if (error) return 'error'\n\n  // no need to check data\n  return \u003cdiv\u003e{data}\u003c/div\u003e\n}\n```\n\n### Multi Query\n\n```jsx\nfunction MultiQuery () {\n  const [foo, fetchFoo] = useQuery(queryFooApi)\n  const [bar, fetchBar] = useQuery(queryBarApi)\n\n  useEffect(() =\u003e {\n    fetchFoo()\n    fetchBar()\n  }, [fetchFoo, fetchBar])\n\n  const renderContent = (state) =\u003e {\n    const { loading, error, data } = state\n\n    if (loading) return 'loading...'\n    if (error) return 'error'\n\n    return \u003cdiv\u003e{data}\u003c/div\u003e\n  }\n\n  return (\n    \u003cdiv\u003e\n      {renderContent(foo)}\n      {renderContent(bar)}\n    \u003c/div\u003e\n  )\n}\n```\n\n### Batch Query\n\n```jsx\nfunction BatchQuery () {\n  const batchFetchApi = () =\u003e Promise.all([queryFooApi(), queryBarApi()])\n  const [{ loading, error, data }, fetch] = useQuery(batchFetchApi)\n\n  useEffect(() =\u003e { fetch() }, [fetch])\n\n  if (loading) return 'loading...'\n  if (error) return 'error'\n\n  const [foo, bar] = data\n\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003e{foo}\u003c/div\u003e\n      \u003cdiv\u003e{bar}\u003c/div\u003e\n      \u003cbutton onClick={fetch}\u003erefetch batch\u003c/button\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n### Mutate\n\n```jsx\nfunction Mutate () {\n  const [{ loading, error, data }, mutate] = useRequest(mutateBazApi)\n  const [value, setValue] = useState('')\n\n  useEffect(() =\u003e {\n    if (error) alert('error')\n    if (data === 'success') alert('success')\n  }, [error, data])\n\n  return (\n    \u003cdiv\u003e\n      \u003cinput value={value} onChange={(e) =\u003e setValue(e.target.value)} /\u003e\n      \u003cbutton disabled={loading} onClick={() =\u003e mutate(value)}\u003esubmit\u003c/button\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n## Api\n\n```ts\ntype useRequest = (api, initialState) =\u003e [state, memoizedRequestCallback]\n```\n\nNotice: Why _momoized_ request callback ?\n\nReference: [Is it safe to omit functions from the list of dependencies?](https://reactjs.org/docs/hooks-faq.html#is-it-safe-to-omit-functions-from-the-list-of-dependencies)\n\nIf you want a deep dive on useEffect and dependencies, it's here: https://overreacted.io/a-complete-guide-to-useeffect/\n\n## Contribution\n\nPR \u0026 issue welcome.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-rekindle%2Fuse-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freact-rekindle%2Fuse-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-rekindle%2Fuse-request/lists"}