{"id":20447645,"url":"https://github.com/acrool/acrool-react-fetcher","last_synced_at":"2025-08-01T01:04:12.713Z","repository":{"id":296860711,"uuid":"856922601","full_name":"acrool/acrool-react-fetcher","owner":"acrool","description":"Axios fetcher provider (react-query, rtk-query), token refresh by Reactjs","archived":false,"fork":false,"pushed_at":"2025-07-06T03:26:11.000Z","size":1109,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-06T03:32:58.356Z","etag":null,"topics":["auth-refreshtoken","axios","graphql","reactjs","restful"],"latest_commit_sha":null,"homepage":"https://acrool-react-fetcher-graphql.pages.dev/","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/acrool.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-09-13T13:15:22.000Z","updated_at":"2025-07-06T03:26:14.000Z","dependencies_parsed_at":"2025-06-03T02:16:39.565Z","dependency_job_id":"98741f0f-80a2-4a03-81ee-b80f219f554c","html_url":"https://github.com/acrool/acrool-react-fetcher","commit_stats":null,"previous_names":["acrool/acrool-react-fetcher"],"tags_count":30,"template":false,"template_full_name":null,"purl":"pkg:github/acrool/acrool-react-fetcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-fetcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-fetcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-fetcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-fetcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acrool","download_url":"https://codeload.github.com/acrool/acrool-react-fetcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acrool%2Facrool-react-fetcher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268151818,"owners_count":24204034,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["auth-refreshtoken","axios","graphql","reactjs","restful"],"created_at":"2024-11-15T10:28:05.344Z","updated_at":"2025-08-01T01:04:12.685Z","avatar_url":"https://github.com/acrool.png","language":"TypeScript","funding_links":[],"categories":["API Utils"],"sub_categories":[],"readme":"# Acrool React Fetcher\n\nAcrool React Fetcher is a solution for API integration and Auth state management in React projects. It helps you easily manage tokens, make API requests, perform GraphQL queries, and handle authentication flows.\n\n\u003ca href=\"https://acrool-react-fetcher.pages.dev/\" title=\"Acrool React Fetcher - This is a block function for React development loading block\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/acrool/acrool-react-fetcher/main/example/public/og.png\" alt=\"Acrool React Fetcher Logo\"/\u003e\n\u003c/a\u003e\n\n\u003cp align=\"center\"\u003e\n    A solution for API integration and token management in React projects\n\u003c/p\u003e\n\n\n- [GraphQL](https://acrool-react-fetcher-graphql.pages.dev/)\n- [RestFul](https://acrool-react-fetcher-restful.pages.dev/)\n\n\n\n\u003cdiv align=\"center\"\u003e\n\n[![NPM](https://img.shields.io/npm/v/@acrool/react-fetcher.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-fetcher)\n[![npm](https://img.shields.io/bundlejs/size/@acrool/react-fetcher?style=for-the-badge)](https://github.com/acrool/@acrool/react-fetcher/blob/main/LICENSE)\n[![npm](https://img.shields.io/npm/l/@acrool/react-fetcher?style=for-the-badge)](https://github.com/acrool/react-fetcher/blob/main/LICENSE)\n\n[![npm downloads](https://img.shields.io/npm/dm/@acrool/react-fetcher.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-fetcher)\n[![npm](https://img.shields.io/npm/dt/@acrool/react-fetcher.svg?style=for-the-badge)](https://www.npmjs.com/package/@acrool/react-fetcher)\n\n\u003c/div\u003e\n\n\n## Features\n\n- Token state management and custom refresh mechanism\n- GraphQL query support and custom fetcher\n- Seamless integration with Redux Toolkit Query\n- Flexible provider composition\n- Easy to test and simulate login/logout/token invalidation scenarios\n\n## Installation\n\n```bash\nyarn add @acrool/react-fetcher\n```\n\n## Quick Start\n\n### 1. Import styles\n\nAdd the following to your entry file (e.g. `index.tsx`):\n\n```ts\nimport \"@acrool/react-fetcher/dist/index.css\";\n```\n\n### 2. Provider structure\n\nWrap your app with `AuthStateProvider` and `AxiosClientProvider`. It is recommended to use `AppFetcherProvider` to automatically wrap all necessary providers:\n\n```tsx\nimport AppFetcherProvider from '@/library/react-fetcher';\n\nReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(\n  \u003cAppFetcherProvider\u003e\n    \u003cApp /\u003e\n  \u003c/AppFetcherProvider\u003e\n);\n```\n\n### 3. Create baseApi (GraphQL query)\n\nFor Redux Toolkit Query, create `baseApi.ts`:\n\n```ts\nimport { createGraphQLFetcher } from '@acrool/react-fetcher';\nimport { createApi } from '@reduxjs/toolkit/query/react';\nimport { axiosInstance } from '@/library/react-fetcher';\n\nexport const baseApi = createApi({\n  reducerPath: 'api',\n  baseQuery: async (query, api, extraOptions) =\u003e {\n    // Token handling and refresh are managed automatically\n    const data = await createGraphQLFetcher(axiosInstance, query.document)(query.args);\n    return { data };\n  },\n  endpoints: () =\u003e ({}),\n});\n```\n\n### 4. Use Auth state and API in your pages\n\n#### Get and update tokens\n\n```tsx\nimport { useAuthState } from '@acrool/react-fetcher';\n\nconst { getTokens, updateTokens } = useAuthState();\n```\n\n#### Send GraphQL query\n\n```tsx\nconst { data, refetch } = useGetBookmarkQuery({ variables: { bookmarkId: '1' } });\n```\n\n#### Simulate token invalidation and refresh\n\n```tsx\nconst handleMockTokenInvalid = () =\u003e {\n  updateTokens(curr =\u003e ({\n    ...curr,\n    accessToken: 'mock-invalid-token',\n  }));\n  refetch();\n};\n```\n\n#### Login/Logout\n\n```tsx\nconst login = useLogin();\nconst logout = useLogout();\n\nawait login({ variables: { input: { account, password } } });\nlogout();\n```\n\n### 5. More examples\n\n- The Dashboard page demonstrates how to operate token, API, and locale switching\n- The Login page demonstrates login and error handling\n\n---\n\n## License\n\nMIT © [Acrool](https://github.com/acrool) \u0026 [Imagine](https://github.com/imagine10255)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facrool%2Facrool-react-fetcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facrool%2Facrool-react-fetcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facrool%2Facrool-react-fetcher/lists"}