{"id":15275841,"url":"https://github.com/zustandjs/zustand-injectors","last_synced_at":"2025-10-13T10:20:56.787Z","repository":{"id":233062169,"uuid":"785924795","full_name":"zustandjs/zustand-injectors","owner":"zustandjs","description":"A sweet way of lazy load slices","archived":false,"fork":false,"pushed_at":"2024-04-14T12:57:52.000Z","size":79,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-21T20:43:42.643Z","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":null,"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":"2024-04-12T23:28:21.000Z","updated_at":"2025-01-30T08:09:35.000Z","dependencies_parsed_at":"2024-04-14T13:43:35.911Z","dependency_job_id":null,"html_url":"https://github.com/zustandjs/zustand-injectors","commit_stats":null,"previous_names":["zustandjs/zustand-injectors"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/zustandjs/zustand-injectors","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-injectors","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-injectors/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-injectors/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-injectors/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zustandjs","download_url":"https://codeload.github.com/zustandjs/zustand-injectors/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zustandjs%2Fzustand-injectors/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279014686,"owners_count":26085554,"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-10-13T02:00:06.723Z","response_time":61,"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":[],"created_at":"2024-09-30T10:07:15.182Z","updated_at":"2025-10-13T10:20:56.740Z","avatar_url":"https://github.com/zustandjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zustand-injectors\n\n[![CI](https://img.shields.io/github/actions/workflow/status/zustandjs/zustand-injectors/ci.yml?branch=main)](https://github.com/zustandjs/zustand-injectors/actions?query=workflow%3ACI)\n[![npm](https://img.shields.io/npm/v/zustand-injectors)](https://www.npmjs.com/package/zustand-injectors)\n[![size](https://img.shields.io/bundlephobia/minzip/zustand-injectors)](https://bundlephobia.com/result?p=zustand-injectors)\n[![discord](https://img.shields.io/discord/627656437971288081)](https://discord.gg/MrQdmzd)\n\nA sweet way to lazy load slices\n\n## Install\n\n```bash\nnpm i zustand zustand-injectors\n```\n\n## Usage\n\n**Auto lazy load slices**\n\n```tsx\n// src/create-decrement-slice.ts\nimport type { StateCreator } from \"zustand\";\n\nimport type { CounterStore } from \"./counter-store\";\n\nexport const createDecrementSlice: StateCreator\u003c\n  CounterStore,\n  [],\n  [],\n  { decrementCount: () =\u003e void }\n\u003e = (set) =\u003e ({\n  decrementCount: () =\u003e {\n    set((currentState) =\u003e ({ count: currentState.count - 1 }));\n  },\n});\n```\n\n```tsx\n// src/counter-store.ts\nimport { createStore } from \"zustand\";\nimport { injectors } from \"zustand-injectors\";\n\nexport type CounterState = { count: number };\n\nexport type CounterActions = {\n  incrementCount: () =\u003e void;\n  decrementCount: () =\u003e void;\n};\n\nexport type CounterStore = CounterState \u0026 CounterActions;\n\nexport const counterStore = createStore\u003cCounterStore\u003e()(\n  injectors(\n    (set) =\u003e ({\n      count: 0,\n      incrementCount: () =\u003e {\n        set((currentState) =\u003e ({ count: currentState.count + 1 }));\n      },\n      decrementCount: () =\u003e {},\n    }),\n    {\n      \"decrement-slice\": () =\u003e\n        import(\"./create-decrement-slice\").then(\n          (mod) =\u003e mod.createDecrementSlice\n        ),\n    }\n  )\n);\n```\n\n```tsx\n// main.tsx\nimport { useLayoutEffect } from \"react\";\nimport { useStore } from \"zustand\";\n\nconst Component = () =\u003e {\n  const { count, incrementCount, decrementCount } = useStore(counterStore);\n\n  return null;\n};\n```\n\n**Manual lazy load slices**\n\n```tsx\n// src/create-decrement-slice.ts\nimport type { StateCreator } from \"zustand\";\n\nimport type { CounterStore } from \"./counter-store\";\n\nexport const createDecrementSlice: StateCreator\u003c\n  CounterStore,\n  [],\n  [],\n  { decrementCount: () =\u003e void }\n\u003e = (set) =\u003e ({\n  decrementCount: () =\u003e {\n    set((currentState) =\u003e ({ count: currentState.count - 1 }));\n  },\n});\n```\n\n```tsx\n// src/counter-store.ts\nimport { useLayoutEffect } from \"react\";\nimport { createStore } from \"zustand\";\nimport { injectors } from \"zustand-injectors\";\n\nexport type CounterState = { count: number };\n\nexport type CounterActions = {\n  incrementCount: () =\u003e void;\n  decrementCount: () =\u003e void;\n};\n\nexport type CounterStore = CounterState \u0026 CounterActions;\n\nexport const counterStore = createStore\u003cCounterStore\u003e()(\n  injectors((set) =\u003e ({\n    count: 0,\n    incrementCount: () =\u003e {\n      set((currentState) =\u003e ({ count: currentState.count + 1 }));\n    },\n    decrementCount: () =\u003e {},\n  }))\n);\n```\n\n```tsx\n// src/main.tsx\nimport { useLayoutEffect } from \"react\";\nimport { useStore } from \"zustand\";\n\nconst Component = () =\u003e {\n  const { count, incrementCount, decrementCount } = useStore(counterStore);\n\n  useLayoutEffect(() =\u003e {\n    counterStore.injectAsyncSliceInitializer(\"decrement-slice\", () =\u003e\n      import(\"./create-decrement-slice\").then((mod) =\u003e mod.createDecrementSlice)\n    );\n  }, []);\n\n  return null;\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzustandjs%2Fzustand-injectors","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzustandjs%2Fzustand-injectors","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzustandjs%2Fzustand-injectors/lists"}