{"id":17480297,"url":"https://github.com/yonathan06/solid-cached-resource","last_synced_at":"2025-04-13T01:20:24.059Z","repository":{"id":45204155,"uuid":"474000712","full_name":"yonathan06/solid-cached-resource","owner":"yonathan06","description":"Cache Solidjs resources by key (derived from the resource source)","archived":false,"fork":false,"pushed_at":"2024-12-12T10:37:21.000Z","size":136,"stargazers_count":38,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T06:50:04.090Z","etag":null,"topics":["cache","solidjs"],"latest_commit_sha":null,"homepage":"https://yonathan06.github.io/solid-cached-resource/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yonathan06.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-25T12:28:36.000Z","updated_at":"2025-01-06T08:47:05.000Z","dependencies_parsed_at":"2024-10-31T14:04:26.135Z","dependency_job_id":"a5822b46-2f36-4893-ba7b-ef5a37030df2","html_url":"https://github.com/yonathan06/solid-cached-resource","commit_stats":{"total_commits":27,"total_committers":3,"mean_commits":9.0,"dds":"0.11111111111111116","last_synced_commit":"bc00bc41924be0af31e55c9c416d5a6256dad1f8"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonathan06%2Fsolid-cached-resource","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonathan06%2Fsolid-cached-resource/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonathan06%2Fsolid-cached-resource/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yonathan06%2Fsolid-cached-resource/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yonathan06","download_url":"https://codeload.github.com/yonathan06/solid-cached-resource/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248651025,"owners_count":21139730,"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","solidjs"],"created_at":"2024-10-18T21:43:17.962Z","updated_at":"2025-04-13T01:20:24.040Z","avatar_url":"https://github.com/yonathan06.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![NPM Version](https://img.shields.io/npm/v/solid-cached-resource) ![npm bundle size](https://img.shields.io/bundlephobia/min/solid-cached-resource) ![NPM License](https://img.shields.io/npm/l/solid-cached-resource)\n\n# Solid Cached Resource\n\nInspired by TanStack Query, with minimal API and footprint, built only for SolidJS.\nThe (almost) same API as [createResource](https://www.solidjs.com/docs/latest/api#createresource).\nIncludes `createMutation` for easier mutation state handling.\n\n[API references](https://yonathan06.github.io/solid-cached-resource/)\n\nFeatures:\n\n- Create resource with the same key in multiple places - fetch once\n- Cache results for next component mount, and refresh when wanted\n- Mutate local resource by key after a successful remote mutation request\n\n## install\n\n```sh\npnpm add solid-cached-resource\n```\n\nor `npm`/`yarn`\n\n## createCachedResource\n\nInspired by [useQuery](https://react-query.tanstack.com/guides/queries) just for Solid `createResource`\n\n```TypeScript\nimport { createCachedResource } from \"solid-cached-resource\";\n\nexport const createGetUserById = (userId: Accessor\u003cstring\u003e) =\u003e {\n  return createCachedResource(\n    () =\u003e [\"user\", userId()],\n    async ([, userId]) =\u003e {\n      const response = await fetch(`/users/${userId}`);\n      return response.json();\n    });\n}\n\n// MyComp.tsx\nconst [user] = createGetUserById(() =\u003e props.userId);\n\n\u003cdiv\u003e{user().name}\u003c/div\u003e\n\n// MyOtherComp.tsx\nconst [user] = createGetUserById(() =\u003e props.userId);\n\n\u003cspan\u003e{user().name}\u003c/span\u003e\n```\n\nIn the case above, if `props.userId` has the same value, the key will be the same, so even though both components are creating the same resource with the same fetcher, only one request will be made to the server.\n\n### With options\n\n`createCachedResource` accepts an optional [options](https://yonathan06.github.io/solid-cached-resource/interfaces/CachedResourceOptions.html) object as its third argument\n\n```TypeScript\n{\n  initialValue?: T (default undefined)\n  refetchOnMount?: boolean (default true)\n}\n```\n\n## createMutations\n\nInspired by [useMutation](https://react-query.tanstack.com/guides/mutations), with onSuccess hook, and `mutateCachedValue` utility function.\n\n```TypeScript\nimport {\n  mutateCachedValue,\n  createMutation,\n} from \"solid-cached-resource\";\n\nexport const createUpdateUser = (userId: Accessor\u003cstring\u003e) =\u003e {\n  return createMutation(async (values) =\u003e {\n    const response = fetch(`user/${userId()}`, {\n      method: \"POST\",\n      body: values,\n    });\n    return await response.json()\n  }, {\n    onSuccess: (user) =\u003e {\n      mutateCachedValue(() =\u003e [\"user\", userId()], user);\n    }\n  });\n}\n```\n\n`mutateCachedValue` will call the resources' `mutate` function with the provided key, so the signals will be updated across your components.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonathan06%2Fsolid-cached-resource","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyonathan06%2Fsolid-cached-resource","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyonathan06%2Fsolid-cached-resource/lists"}