{"id":25443953,"url":"https://github.com/wasabi315/react-use-actions","last_synced_at":"2026-05-01T12:32:51.917Z","repository":{"id":42846087,"uuid":"262625393","full_name":"wasabi315/react-use-actions","owner":"wasabi315","description":null,"archived":false,"fork":false,"pushed_at":"2023-01-06T05:25:35.000Z","size":2636,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-11T10:04:59.061Z","etag":null,"topics":["react","react-hooks","typescript","use-reducer"],"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/wasabi315.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":"2020-05-09T17:40:53.000Z","updated_at":"2021-12-14T11:44:21.000Z","dependencies_parsed_at":"2023-02-05T10:16:48.273Z","dependency_job_id":null,"html_url":"https://github.com/wasabi315/react-use-actions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/wasabi315/react-use-actions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabi315%2Freact-use-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabi315%2Freact-use-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabi315%2Freact-use-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabi315%2Freact-use-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasabi315","download_url":"https://codeload.github.com/wasabi315/react-use-actions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasabi315%2Freact-use-actions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32497812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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","typescript","use-reducer"],"created_at":"2025-02-17T15:18:02.056Z","updated_at":"2026-05-01T12:32:51.899Z","avatar_url":"https://github.com/wasabi315.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-use-actions\n\n[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/tterb/atomic-design-ui/blob/master/LICENSEs)\n![](https://github.com/wasabi315/react-use-actions/workflows/CI/badge.svg)\n[![David](https://david-dm.org/tterb/Hyde.svg)](https://david-dm.org/tterb/Hyde)\n\n\u003e Just another style of `useReducer`\n\nIn this `react-use-actions` world, we define the `reducer` like\n\n```ts\nconst actions = defineActions\u003cState\u003e()({\n  increment: state =\u003e ({ count: state.count + 1 })\n  ...\n})\n```\n\ninstead of\n\n```ts\nconst reducer = (state, action) =\u003e {\n  switch (action.type) {\n    case 'INCREMENT':\n      return { count: state.count + 1 }\n    ...\n  }\n}\n```\n\nand invoke the `dispatch` with method call style\n\n```ts\nconst onClick = () =\u003e dispatch.increment()\n```\n\ninstead of\n\n```ts\nconst onClick = () =\u003e dispatch({ type: 'INCREMENT' })\n```\n\nSince the **dispatch object** is fully typed, this style helps editors' autocompletion:heart_eyes:\n\n## Installation\n\n```sh\n$ npm i --save react-use-actions\n# or\n$ yarn add react-use-actions\n```\n\n## Example\n\n```tsx\nimport React from 'react'\nimport { render } from 'react-dom'\nimport { defineActions, useActions } from 'react-use-actions'\n\ninterface State {\n  count: number\n}\n\nconst actions = defineActions\u003cState\u003e()({\n  decrement: state =\u003e ({ count: state.count - 1 }),\n  increment: state =\u003e ({ count: state.count + 1 }),\n})\n\nconst App: React.FC = () =\u003e {\n  const [state, dispatch] = useActions(actions, 0)\n  return (\n    \u003cdiv\u003e\n      \u003cbutton onClick={dispatch.decrement}\u003e-\u003c/button\u003e\n      \u003cspan\u003ecount = {state.count}\u003c/span\u003e\n      \u003cbutton onClick={dispatch.increment}\u003e+\u003c/button\u003e\n    \u003c/div\u003e\n  )\n}\n\nrender(\u003cApp /\u003e, document.getElementById('root'))\n```\n\n## API\n\n### `defineActions()(actions)`\n\n```ts\ninterface State {\n  ...\n}\n\nconst actions = defineActions\u003cState\u003e()({\n  foo: state =\u003e { /* 'state' is typed as 'State' here */ return ... },\n  // You can pass arguments to actions\n  bar: (state, arg1: T1, arg2: T2) =\u003e { return ... },\n  // Optional argument and variable length argument are allowed\n  baz: (state, arg3: T3 = t3, ...arg4: T4[]) =\u003e { return ... },\n})\n```\n\nA no-op behavior-wise function. This function is provided only for type inference.\n\n### `useActions(actions, intialState)`\n\n```tsx\nconst SomeComponent = () =\u003e {\n  const [state, dispatch] = useActions(actions, initialState)\n  ...\n  return (\n    \u003c\u003e\n      {/* 'dispatch' is fully typed! */}\n      \u003cbutton onClick={() =\u003e dispatch.foo()}\u003efoo\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e dispatch.bar(arg1, arg2)}\u003efoo\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e dispatch.baz(arg3, arg41, arg42)}\u003efoo\u003c/button\u003e\n    \u003c/\u003e\n  )\n}\n```\n\nYou can create an initial state lazily as with the original API of `useReducer`.\n\n```ts\nconst [state, dispatch] = useActions(actions, initialArg, initializer)\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasabi315%2Freact-use-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasabi315%2Freact-use-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasabi315%2Freact-use-actions/lists"}