{"id":24953310,"url":"https://github.com/fredericoo/zustand-context","last_synced_at":"2025-04-10T15:26:36.966Z","repository":{"id":237257099,"uuid":"794143052","full_name":"fredericoo/zustand-context","owner":"fredericoo","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-22T19:42:58.000Z","size":81,"stargazers_count":42,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T12:58:36.278Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fredericoo.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","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":"2024-04-30T14:34:38.000Z","updated_at":"2025-03-24T06:28:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"0cc57ebf-d7ed-412c-af80-f4e0e131be85","html_url":"https://github.com/fredericoo/zustand-context","commit_stats":null,"previous_names":["fredericoo/zustand-context"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Fzustand-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Fzustand-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Fzustand-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fredericoo%2Fzustand-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fredericoo","download_url":"https://codeload.github.com/fredericoo/zustand-context/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248243445,"owners_count":21071054,"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":"2025-02-03T03:33:57.712Z","updated_at":"2025-04-10T15:26:36.926Z","avatar_url":"https://github.com/fredericoo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zustand Context\n\nZustand context is a **super tiny (281 bytes gzipped)** and easy way to create a context-aware zustand store. With this you may determine an initial value for your store and use it in your components with isolated instances.\n\n## Creating a Context-aware Zustand Store\n```ts\ntype Cat = string\n\ntype CatStore = {\n  cats: Cat[];\n  addCat: (cat: Cat) =\u003e void;\n  removeCat: (cat: Cat) =\u003e void;\n}\n\nexport const [CatsProvider, useCatsStore] = createZustandContext(\n\t(initialState: { cats: Cat[] }) =\u003e\n\t\tcreate\u003cCatStore\u003e(set =\u003e ({\n\t\t\tcats: initialState.cats,\n\t\t\taddCat: cat =\u003e set(state =\u003e ({ cats: [...state.cats, cat] })),\n      removeCat: cat =\u003e set(state =\u003e ({ cats: state.cats.filter(c =\u003e c !== cat) })),\n\t\t})),\n);\n```\n\n## Consuming a Context-aware Zustand Store\n\n```tsx\nconst App = () =\u003e {\n  return \u003cCatsProvider initialValue={{ cats: [\"Salem\", \"Mimo\", \"Tapi\"] }}\u003e\n    \u003cCatsList /\u003e\n  \u003c/CatsProvider\u003e\n}\n\nconst CatsList = () =\u003e {\n  /** Exact same api as zustand */\n  const cats = useCatsStore(state =\u003e state.cats);\n\n  return \u003cul\u003e\n    {cats.map(cat =\u003e \u003cli key={cat}\u003e{cat}\u003c/li\u003e)}\n  \u003c/ul\u003e\n}\n```\n\n## Contributing\n\nThis project is open to contributions. Feel free to open an issue or a pull request.\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredericoo%2Fzustand-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffredericoo%2Fzustand-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffredericoo%2Fzustand-context/lists"}