{"id":17004285,"url":"https://github.com/pedrobern/react-hook-use-cancelable-thunk-reducer","last_synced_at":"2025-09-09T11:43:31.821Z","repository":{"id":36548034,"uuid":"228227976","full_name":"PedroBern/react-hook-use-cancelable-thunk-reducer","owner":"PedroBern","description":"React Hook useReducer with cancelable dispatch of thunks","archived":false,"fork":false,"pushed_at":"2023-01-05T03:03:47.000Z","size":851,"stargazers_count":26,"open_issues_count":16,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-06T05:49:33.885Z","etag":null,"topics":["react","react-hooks","redux","thunk","usereducer"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/PedroBern.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}},"created_at":"2019-12-15T18:03:27.000Z","updated_at":"2022-05-12T13:02:13.000Z","dependencies_parsed_at":"2023-01-17T02:30:59.999Z","dependency_job_id":null,"html_url":"https://github.com/PedroBern/react-hook-use-cancelable-thunk-reducer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/PedroBern/react-hook-use-cancelable-thunk-reducer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroBern%2Freact-hook-use-cancelable-thunk-reducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroBern%2Freact-hook-use-cancelable-thunk-reducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroBern%2Freact-hook-use-cancelable-thunk-reducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroBern%2Freact-hook-use-cancelable-thunk-reducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PedroBern","download_url":"https://codeload.github.com/PedroBern/react-hook-use-cancelable-thunk-reducer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PedroBern%2Freact-hook-use-cancelable-thunk-reducer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274291331,"owners_count":25258157,"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-09-09T02:00:10.223Z","response_time":80,"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","redux","thunk","usereducer"],"created_at":"2024-10-14T04:43:14.693Z","updated_at":"2025-09-09T11:43:31.801Z","avatar_url":"https://github.com/PedroBern.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-cancelable-thunk-reducer\n\n[![Codecov Coverage](https://img.shields.io/codecov/c/github/pedrobern/react-hook-use-cancelable-thunk-reducer/master.svg?style=flat-square)](https://codecov.io/gh/pedrobern/react-hook-use-cancelable-thunk-reducer/)\n[![Build Status](https://travis-ci.com/pedrobern/react-hook-use-cancelable-thunk-reducer.svg?branch=master)](https://travis-ci.com/pedrobern/react-hook-use-cancelable-thunk-reducer)\n[![dependencies](https://david-dm.org/pedrobern/react-hook-use-cancelable-thunk-reducer.svg)](https://github.com/pedrobern/react-hook-use-cancelable-thunk-reducer)\n\nCustom implementation of react hook `useReducer` that will cancel all dispatched actions if the component is unmounted and allows to dispatch [thunk actions](https://github.com/reduxjs/redux-thunk) (that will be canceled either).\n\n\u003c!-- ![demo-gif](https://github.com/pedrobern/react-tiger-transition/raw/master/demo.gif) --\u003e\n![demo-gif](/demo.gif)\n\nOpen on [codesanbox](https://codesandbox.io/s/use-cancelable-thunk-reducer-lirs9).\n\n## Installation\n\n```\nyarn add use-cancelable-thunk-reducer\n\nnpm i use-cancelable-thunk-reducer\n```\n\n## useCancelableThunkReducer\n\n```javascript\nimport useCancelableThunkReducer from 'use-cancelable-thunk-reducer';\n\nconst [state, dispatch] = useCancelableThunkReducer(\n  reducer,\n  initialState,\n  callback,\n  init\n);\n\n```\n\n### `reducer`\n\nuseReducer first argument.\n\n### `initialState`\nuseReducer second argument.\n\n### `callback`\ndefault is `undefined`, if is a `function`, when some action is canceled it is called with the action argument: `callback(action)`.\n\n### `init`\nuseReducer last argument.\n\n## Thunk action\n\nThe thunk actions receive `(dispatch, getState)` args.\n\n```javascript\nconst thunkAction = args =\u003e async (dispatch, getState) =\u003e {\n  dispatch({type: ACTION_SENT});\n  const state = getState();\n  ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrobern%2Freact-hook-use-cancelable-thunk-reducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpedrobern%2Freact-hook-use-cancelable-thunk-reducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpedrobern%2Freact-hook-use-cancelable-thunk-reducer/lists"}