{"id":16527386,"url":"https://github.com/sosukesuzuki/use-thunk-reducer","last_synced_at":"2025-10-28T10:30:50.166Z","repository":{"id":98706169,"uuid":"172736328","full_name":"sosukesuzuki/use-thunk-reducer","owner":"sosukesuzuki","description":"A Hook that enhanced useReducer with like redux-thunk.","archived":false,"fork":false,"pushed_at":"2019-02-26T15:18:39.000Z","size":107,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-08T18:12:18.903Z","etag":null,"topics":["react","reacthooks"],"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/sosukesuzuki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2019-02-26T15:18:17.000Z","updated_at":"2022-03-04T13:48:59.000Z","dependencies_parsed_at":"2023-05-07T07:30:30.018Z","dependency_job_id":null,"html_url":"https://github.com/sosukesuzuki/use-thunk-reducer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sosukesuzuki/use-thunk-reducer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sosukesuzuki%2Fuse-thunk-reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sosukesuzuki%2Fuse-thunk-reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sosukesuzuki%2Fuse-thunk-reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sosukesuzuki%2Fuse-thunk-reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sosukesuzuki","download_url":"https://codeload.github.com/sosukesuzuki/use-thunk-reducer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sosukesuzuki%2Fuse-thunk-reducer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281424581,"owners_count":26499020,"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-28T02:00:06.022Z","response_time":60,"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","reacthooks"],"created_at":"2024-10-11T17:35:11.714Z","updated_at":"2025-10-28T10:30:50.161Z","avatar_url":"https://github.com/sosukesuzuki.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# useThunkReducer\n\nA Hook that enhanced `useReducer` with like `redux-thunk`.\n\n## Why?\n\nReact provides `useReducer`. It make we can use reducer to mange state in React. However, It isn't allow using middleware. So, we cannot use `redux-thunk` with useReducer. So, I implemented new `useReducer` that enhanced with like `redux-thunk`.\n\n## Usage\n\nImplement reducer as same as for normal `useReducer`.\n\n```ts\ntype State = { count: number };\ntype Action = { type: \"increase\"; amount: number };\n\nfunction reducer(state: State, action: Action): State {\n  switch (action.type) {\n    case \"increase\":\n      return { count: state.count + action.amount };\n    default:\n      throw new Error();\n  }\n}\n```\n\nDeclare async action like for `redux-thunk`.(But, second argument is not `getState`.)\n\n```ts\nconst increaseAsync = (amount: number) =\u003e {\n  return (dispatch: React.Dispatch\u003cAction\u003e, state: State) =\u003e {\n    setTimeout(() =\u003e {\n      console.log(state);\n      dispatch({ type: \"increase\", amount });\n    }, 1000);\n  };\n};\n```\n\nImplement Counter component.\n\n```tsx\nconst initialState: State = { count: 0 };\n\nfunction Counter() {\n  const [state, dispatch] = useThunkReducer(reducer, initialState);\n  const increaseTwoWithOneSecond = React.useCallback(\n    () =\u003e dispatch(increaseAsync(2)),\n    []\n  );\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{state.count}\u003c/p\u003e\n      \u003cbutton onClick={increaseTwoWithOneSecond}\u003e\n        increase 2 with 1 second\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsosukesuzuki%2Fuse-thunk-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsosukesuzuki%2Fuse-thunk-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsosukesuzuki%2Fuse-thunk-reducer/lists"}