{"id":19427062,"url":"https://github.com/frolleks/cache-fetcher","last_synced_at":"2025-02-25T05:17:48.177Z","repository":{"id":187868608,"uuid":"677727393","full_name":"frolleks/cache-fetcher","owner":"frolleks","description":"A dead simple data fetcher for JavaScript, React, and Solid.js","archived":false,"fork":false,"pushed_at":"2023-08-17T03:39:14.000Z","size":105,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T16:47:54.145Z","etag":null,"topics":["cache-fetcher","http","nodejs","react","requests","solid"],"latest_commit_sha":null,"homepage":"https://cache-fetcher.vercel.app/","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/frolleks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2023-08-12T12:41:39.000Z","updated_at":"2023-08-16T14:42:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"79a79186-b850-4cfa-b0de-d090e684091a","html_url":"https://github.com/frolleks/cache-fetcher","commit_stats":null,"previous_names":["frolleks/cache-fetcher"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frolleks%2Fcache-fetcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frolleks%2Fcache-fetcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frolleks%2Fcache-fetcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frolleks%2Fcache-fetcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frolleks","download_url":"https://codeload.github.com/frolleks/cache-fetcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240605841,"owners_count":19827985,"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":["cache-fetcher","http","nodejs","react","requests","solid"],"created_at":"2024-11-10T14:10:14.219Z","updated_at":"2025-02-25T05:17:48.122Z","avatar_url":"https://github.com/frolleks.png","language":"TypeScript","readme":"# cache-fetcher\n\n[![npm](https://img.shields.io/npm/v/cache-fetcher)](https://npmjs.org/package/cache-fetcher)\n![npm](https://img.shields.io/npm/dm/cache-fetcher)\n\nA dead simple and opinionated data fetcher for JavaScript, React, and Solid.js.\n\n## Installation\n\n**npm:** `npm i cache-fetcher`\n\n**yarn:** `yarn add cache-fetcher`\n\n**pnpm:** `pnpm add cache-fetcher`\n\n## Usage\n\n### JavaScript\n\nSimply import it,\n\n```js\nimport * as cacheFetcher from \"cache-fetcher\";\n```\n\nand make a request.\n\n```js\nconst res = await cacheFetcher.get(\n  \"https://jsonplaceholder.typicode.com/todos/1\"\n);\n\nif (res.isLoading) console.log(\"Loading...\");\nelse console.log(res.data);\n\nif (res.error) console.log(res.error);\n\n// or like this:\n\nconst { data, isLoading, error } = await cacheFetcher.get(\n  \"https://jsonplaceholder.typicode.com/todos/1\"\n);\n\nif (isLoading) console.log(\"Loading...\");\nelse console.log(data);\n\nif (error) console.log(error);\n```\n\n### React\n\nImport the `useCacheFetcher` hook,\n\n```js\nimport { useCacheFetcher } from \"cache-fetcher/react\";\n```\n\nand make a request.\n\n```jsx\nfunction MyComponent() {\n  // Let's say you want to fetch some data from this URL\n  const url = \"https://api.example.com/data\";\n\n  // Just call the useCacheFetcher hook with that URL\n  const { data, isLoading, error } = useCacheFetcher(url);\n\n  // Now you can handle the various states your data might be in:\n  if (isLoading) {\n    return \u003cdiv\u003eLoading...\u003c/div\u003e;\n  }\n\n  if (error) {\n    return \u003cdiv\u003eError: {error?.message}\u003c/div\u003e;\n  }\n\n  // Render your data!\n  return (\n    \u003cdiv\u003e\n      \u003ch1\u003eData Loaded!\u003c/h1\u003e\n      \u003cpre\u003e{JSON.stringify(data, null, 2)}\u003c/pre\u003e\n    \u003c/div\u003e\n  );\n}\n\nexport default MyComponent;\n```\n\n### Solid.js\n\nImport the `createCacheFetcher` function,\n\n```js\nimport { createCacheFetcher } from \"cache-fetcher/solid\";\n```\n\nand make a request.\n\n```jsx\nfunction MyComponent() {\n  // Let's say you want to fetch some data from this URL\n  const url = \"https://api.example.com/data\";\n\n  // Just call the createCacheFetcher function with that URL\n  const { data, isLoading, error } = createCacheFetcher(url);\n\n  // Now you can handle the various states your data might be in:\n  if (isLoading) {\n    return \u003cdiv\u003eLoading...\u003c/div\u003e;\n  }\n\n  if (error) {\n    return \u003cdiv\u003eError: {error?.message}\u003c/div\u003e;\n  }\n\n  // Render your data!\n  return (\n    \u003cdiv\u003e\n      \u003ch1\u003eData Loaded!\u003c/h1\u003e\n      \u003cpre\u003e{JSON.stringify(data, null, 2)}\u003c/pre\u003e\n    \u003c/div\u003e\n  );\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrolleks%2Fcache-fetcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrolleks%2Fcache-fetcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrolleks%2Fcache-fetcher/lists"}