{"id":19945729,"url":"https://github.com/sasa-djuric/react-use-slice","last_synced_at":"2026-05-06T01:37:04.795Z","repository":{"id":57347204,"uuid":"372264217","full_name":"sasa-djuric/react-use-slice","owner":"sasa-djuric","description":"A react hook to use reducers with an API like createSlice from Redux toolkit, in a typesafe way, with performance in mind.","archived":false,"fork":false,"pushed_at":"2021-12-09T15:07:44.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-26T20:53:57.386Z","etag":null,"topics":["react","react-hooks","reducer","redux","state-management","typescript","use-reducer"],"latest_commit_sha":null,"homepage":"","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/sasa-djuric.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}},"created_at":"2021-05-30T16:31:28.000Z","updated_at":"2023-03-09T00:23:04.000Z","dependencies_parsed_at":"2022-09-18T17:51:06.130Z","dependency_job_id":null,"html_url":"https://github.com/sasa-djuric/react-use-slice","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sasa-djuric/react-use-slice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasa-djuric%2Freact-use-slice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasa-djuric%2Freact-use-slice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasa-djuric%2Freact-use-slice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasa-djuric%2Freact-use-slice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sasa-djuric","download_url":"https://codeload.github.com/sasa-djuric/react-use-slice/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sasa-djuric%2Freact-use-slice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278457470,"owners_count":25989955,"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-05T02:00:06.059Z","response_time":54,"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":["react","react-hooks","reducer","redux","state-management","typescript","use-reducer"],"created_at":"2024-11-13T00:26:45.400Z","updated_at":"2025-10-05T12:52:14.795Z","avatar_url":"https://github.com/sasa-djuric.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-use-slice\n\nA react hook to use reducers with an API like createSlice from Redux toolkit, in a typesafe way, with performance in mind.\n\n## Install\n\n```sh\nnpm install react-use-slice\n```\n\n## Example\n\n#### JavaScript\n\n```js\nimport { createContext } from 'react';\nimport useSlice from 'react-use-slice';\n\nconst initialState = {\n  score: 0\n};\n\nconst scoreSlice = {\n  name: 'score', // \"name\" is optional. It is used in dev tools\n  initialState,\n  reducers: {\n    increment(state, payload) {\n      const score = state.score + 1;\n      return { ...state, score };\n    },\n    decrement(state, payload) {\n      const score = state.score - 1;\n      return { ...state, score };\n    }\n  }\n};\n\nexport const ScoreContext = createContext(null);\n\nexport const ScoreProvider = ({ children }) =\u003e {\n  // Actions will be automaticaly dispatched\n  const [state, actions] = useSlice(scoreSlice);\n\n  return (\n    \u003cScoreContext.Provider value={{ ...state, ...actions }}\u003e\n      {children}\n    \u003c/ScoreContext.Provider\u003e\n  );\n};\n```\n\n#### TypeScript\n\n```ts\nimport { createContext } from 'react';\nimport useSlice, { createSlice, CombineStateAndActions } from 'react-use-slice';\n\nconst initialState = {\n  score: 0\n};\n\nconst scoreSlice = createSlice({\n  name: 'score', // \"name\" is optional. It is used in dev tools\n  initialState,\n  reducers: {\n    increment(state, payload: number) {\n      const score = state.score + 1;\n      return { ...state, score };\n    },\n    decrement(state, payload: number) {\n      const score = state.score - 1;\n      return { ...state, score };\n    }\n  }\n});\n\nexport const ScoreContext =\n  createContext\u003cCombineStateAndActions\u003ctypeof scoreSlice\u003e | null\u003e(null);\n\nexport const ScoreProvider = ({ children }) =\u003e {\n  // Actions will be automaticaly dispatched\n  const [state, actions] = useSlice(scoreSlice);\n\n  return (\n    \u003cScoreContext.Provider value={{ ...state, ...actions }}\u003e\n      {children}\n    \u003c/ScoreContext.Provider\u003e\n  );\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasa-djuric%2Freact-use-slice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsasa-djuric%2Freact-use-slice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsasa-djuric%2Freact-use-slice/lists"}