{"id":15275826,"url":"https://github.com/zustandjs/derive-zustand","last_synced_at":"2025-04-09T11:12:46.017Z","repository":{"id":65900921,"uuid":"562503767","full_name":"zustandjs/derive-zustand","owner":"zustandjs","description":"A function to create a derived Zustand store from stores","archived":false,"fork":false,"pushed_at":"2024-07-04T00:27:20.000Z","size":209,"stargazers_count":106,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T06:22:15.528Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/zustandjs.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-06T15:08:07.000Z","updated_at":"2024-09-24T02:01:32.000Z","dependencies_parsed_at":"2024-11-13T04:36:12.294Z","dependency_job_id":"a43964d8-ff54-449b-aa5c-4b10cdf35dfd","html_url":"https://github.com/zustandjs/derive-zustand","commit_stats":{"total_commits":16,"total_committers":2,"mean_commits":8.0,"dds":0.1875,"last_synced_commit":"2cf1750726e3dd31e8f339eff6650152f6f9d8db"},"previous_names":["dai-shi/derive-zustand"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fderive-zustand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fderive-zustand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fderive-zustand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fderive-zustand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zustandjs","download_url":"https://codeload.github.com/zustandjs/derive-zustand/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248027411,"owners_count":21035594,"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-09-30T10:06:45.670Z","updated_at":"2025-04-09T11:12:45.999Z","avatar_url":"https://github.com/zustandjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# derive-zustand\n\n[![CI](https://img.shields.io/github/actions/workflow/status/dai-shi/derive-zustand/ci.yml?branch=main)](https://github.com/dai-shi/derive-zustand/actions?query=workflow%3ACI)\n[![npm](https://img.shields.io/npm/v/derive-zustand)](https://www.npmjs.com/package/derive-zustand)\n[![size](https://img.shields.io/bundlephobia/minzip/derive-zustand)](https://bundlephobia.com/result?p=derive-zustand)\n[![discord](https://img.shields.io/discord/627656437971288081)](https://discord.gg/MrQdmzd)\n\nA function to create a derived [Zustand](https://github.com/pmndrs/zustand) store from stores\n\n## Install\n\n```bash\nnpm install zustand derive-zustand\n```\n\n## Usage\n\n```tsx\nimport { create, useStore } from 'zustand';\nimport { derive } from 'derive-zustand';\n\nconst useCountStore = create\u003c{ count: number; inc: () =\u003e void }\u003e((set) =\u003e ({\n  count: 0,\n  inc: () =\u003e set((state) =\u003e ({ count: state.count + 1 })),\n}));\n\nconst doubleCountStore = derive\u003cnumber\u003e((get) =\u003e get(useCountStore).count * 2);\nconst useDoubleCountStore = () =\u003e useStore(doubleCountStore);\n\nconst Counter = () =\u003e {\n  const { count, inc } = useCountStore();\n  const doubleCount = useDoubleCountStore();\n  return (\n    \u003cdiv\u003e\n      \u003cdiv\u003ecount: {count}\u003c/div\u003e\n      \u003cdiv\u003edoubleCount: {doubleCount}\u003c/div\u003e\n      \u003cbutton type=\"button\" onClick={inc}\u003e\n        +1\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n## Examples\n\nThe [examples](examples) folder contains working examples.\nYou can run one of them with\n\n```bash\nPORT=8080 pnpm run examples:01_counter\n```\n\nand open \u003chttp://localhost:8080\u003e in your web browser.\n\nYou can also try them directly:\n[01](https://stackblitz.com/github/zustandjs/derive-zustand/tree/main/examples/01_counter)\n[02](https://stackblitz.com/github/zustandjs/derive-zustand/tree/main/examples/02_animals)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzustandjs%2Fderive-zustand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzustandjs%2Fderive-zustand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzustandjs%2Fderive-zustand/lists"}