{"id":17888091,"url":"https://github.com/soywod/react-use-bireducer","last_synced_at":"2025-10-23T14:30:24.867Z","repository":{"id":39675231,"uuid":"496577188","full_name":"soywod/react-use-bireducer","owner":"soywod","description":"React hook for managing effectful reducers.","archived":false,"fork":false,"pushed_at":"2022-05-27T20:39:05.000Z","size":238,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-15T22:29:11.248Z","etag":null,"topics":["react","react-effect","react-hook","react-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/soywod.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":"SECURITY.md","support":null}},"created_at":"2022-05-26T10:32:53.000Z","updated_at":"2024-07-03T17:41:28.000Z","dependencies_parsed_at":"2022-09-20T07:24:29.437Z","dependency_job_id":null,"html_url":"https://github.com/soywod/react-use-bireducer","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-use-bireducer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-use-bireducer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-use-bireducer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soywod%2Freact-use-bireducer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soywod","download_url":"https://codeload.github.com/soywod/react-use-bireducer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237839050,"owners_count":19374306,"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","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-effect","react-hook","react-reducer"],"created_at":"2024-10-28T13:36:32.350Z","updated_at":"2025-10-23T14:30:24.362Z","avatar_url":"https://github.com/soywod.png","language":"TypeScript","funding_links":["https://github.com/sponsors/soywod","https://www.paypal.com/paypalme/soywod","https://ko-fi.com/soywod","https://www.buymeacoffee.com/soywod","https://liberapay.com/soywod"],"categories":[],"sub_categories":[],"readme":"# 🔀 React use bireducer [![tests](https://img.shields.io/github/workflow/status/soywod/react-use-bireducer/integration?label=tests\u0026logo=github\u0026style=flat-square)](https://github.com/soywod/react-use-bireducer/actions/workflows/test.yaml) [![codecov](https://img.shields.io/codecov/c/github/soywod/react-use-bireducer?logo=codecov\u0026style=flat-square)](https://app.codecov.io/gh/soywod/react-use-bireducer) [![npm](https://img.shields.io/npm/v/react-use-bireducer?logo=npm\u0026label=npm\u0026color=success\u0026style=flat-square)](https://www.npmjs.com/package/react-use-bireducer)\n\nReact hook for managing effectful reducers.\n\n## Motivation\n\nWhen your application gets bigger, it is hard to manage both state\nchanges and effectful computations. I find the Model-View-Update\npattern (which the [Elm\narchitecture](https://guide.elm-lang.org/architecture/) is based on)\nreally effective for this kind of task. `useBireducer` implements this\npattern by combining two reducers (hence the name): a state reducer\nand an effect reducer.\n\nThe state reducer is really close to `useReducer`, except that it\nreturns the new state AND the effects to execute:\n\n```typescript\ntype StateReducer\u003cS, A, E\u003e = (state: S, action: A) =\u003e [S, Array\u003cE\u003e];\n```\n\nThe effect reducer just executes effects and can return a cleanup\nfunction. This cleanup function is called when the component unmounts:\n\n```typescript\ntype EffectReducer\u003cE, A\u003e = (effect: E, dispatch: React.Dispatch\u003cA\u003e) =\u003e void | (() =\u003e void);\n```\n\nThis pattern helps you to separate state changes from effectful\ncomputations. It also makes your tests stronger.\n\n## Installation\n\n```bash\nyarn add react-use-bireducer\n# or\nnpm install react-use-bireducer\n```\n\n## Usage\n\n```typescript\nimport {useBireducer} from \"react-use-bireducer\";\n\nconst [state, dispatch] = useBireducer(stateReducer, effectReducer, defaultState);\n```\n\nSee a complete example on\n[CodeSandbox](https://codesandbox.io/s/react-use-bireducer-example-20n30w?file=/src/App.tsx).\n\nIf you want to see an example in a real world application, have a look\nat\n[react-pin-field](https://github.com/soywod/react-pin-field/blob/49418994ae39c3aac67d2b4f94082a20effcea4b/lib/src/pin-field/pin-field.tsx#L251).\n\n## Development\n\nDevelopment environment is managed by [Nix](https://nixos.org/). First\nyou need to install it:\n\n```bash\ncurl -L https://nixos.org/nix/install | sh\n```\n\nThen you can start your development environment by spawning a Nix\nshell:\n\n```bash\nnix-shell\n```\n\nNow you should be able to clone the repo and install Node.js\ndependencies:\n\n```bash\ngit clone https://github.com/soywod/react-use-bireducer.git\ncd react-use-bireducer\nyarn\n```\n\nYou can leave the development environment either by killing your\nterminal or by entering the command `exit`.\n\n## Tests\n\nTests are handled by [Jest](https://jestjs.io/) (`.test` files) and\n[React Testing\nLibrary](https://testing-library.com/docs/react-testing-library/intro/)\n(`.spec` files).\n\n```bash\nyarn test\n```\n\n## Similar projects\n\n- [`useEffectReducer`](https://github.com/davidkpiano/useEffectReducer):\n  the state reducer exposes a third argument called `exec` to schedule\n  effects\n- [`useElmish`](https://github.com/ncthbrt/react-use-elmish): it is a\n  mix between `useEffectReducer` and `useBireducer`\n\n## Sponsoring\n\n[![github](https://img.shields.io/badge/-GitHub%20Sponsors-fafbfc?logo=GitHub%20Sponsors\u0026style=flat-square)](https://github.com/sponsors/soywod)\n[![paypal](https://img.shields.io/badge/-PayPal-0079c1?logo=PayPal\u0026logoColor=ffffff\u0026style=flat-square)](https://www.paypal.com/paypalme/soywod)\n[![ko-fi](https://img.shields.io/badge/-Ko--fi-ff5e5a?logo=Ko-fi\u0026logoColor=ffffff\u0026style=flat-square)](https://ko-fi.com/soywod)\n[![buy-me-a-coffee](https://img.shields.io/badge/-Buy%20Me%20a%20Coffee-ffdd00?logo=Buy%20Me%20A%20Coffee\u0026logoColor=000000\u0026style=flat-square)](https://www.buymeacoffee.com/soywod)\n[![liberapay](https://img.shields.io/badge/-Liberapay-f6c915?logo=Liberapay\u0026logoColor=222222\u0026style=flat-square)](https://liberapay.com/soywod)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoywod%2Freact-use-bireducer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoywod%2Freact-use-bireducer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoywod%2Freact-use-bireducer/lists"}