Abstract multiple state actions into a single store function
Hana allows you easily set and get your global state using the useStore() hook, and while this is super easy, it quickly gets annoying if you have to work with multiple state values, especially if they are all working towards the same feature.Reducers allow you to abstract all that into a single function which can be called from anywhere in your app, using the useReducer() hook.
Hana reducers are registered globally so they can be used anywhere in your app without carrying over the entire function as done in other reducer implementations. In Hana, all you need is the reducer name. You can register the reducer globally using:
The createStore() function right on init
useReducer() but this can cause problems if not done right
createStore() is OPTIONALLY used to initialize your global store with default options like the initial state, reducers, modules and other items. To add reducers, you can either use a module or pass the reducer directly like this:
The example above registers a reducer called setItems that reverses the order of the items in the state object and adds the payload to the end of the array. This reducer can be used in any component using the useReducer() hook, but we will get to that later.
This hook takes in the reducer function you want to register, and uses the name of the function as the name of the reducer. This means that the name of the reducer function must be the same as the name of the reducer you want to register.
We recommend using createStore() to register all your reducers instead of useReducer() because this method heavily depends on execution order. If the user calls a component that requires the reducer before it is registered, you could break your application. You should use this method to register your reducers ONLY if you can guarantee the correct execution order
In this case, the reducer is passed directly to useReducer() . It will take the function name which is setItems() in this case, and register it globally so you can use it in other components without needing to export the function first:
import { useReducer } from '@hanabira/store';const Component = () => { const setItems = useReducer('setItems'); // items is an array of items the user wants to add to the list const addItemsToList = (items) => { setItems(items); }; ...};
Remember that this will only work if the component with the initial useReducer() is called first
After registering your reducer globally, the easy part is using your reducer to do all the cool magical state updates with just one function. Let’s look at an example where some data is collected from an API response and synced to state:
While this is a super simple example and will probably not happen much in production, the idea is the same. Reducers allow you to define some actions that return a new state and are usually used for complex flows.
Most implementations of reducers force you to pass a payload into your reducer function, but that’s totally optional with Hana. This allows you to define self-contained reducers that perform and internal action and update the state, for example, a logout action:
Sometimes, you may need to use a reducer in a component that does not actually re-render the UI after the reducer is called. In this case, you can use the useStaticReducer() hook. It works exactly like the useReducer() hook, but it does not cause the component to re-render when the reducer is called.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Hana","colors":{"primary":"#C391D9","light":"#7B8FD6","dark":"#5A75C4"},"logo":{"light":"https://mintcdn.com/selll/vG17S6xpomHf6obv/logo/hanabira-by-leaf-regular.png?fit=max\u0026auto=format\u0026n=vG17S6xpomHf6obv\u0026q=85\u0026s=1d1682b7a27193710c61a64497e12a70","dark":"https://mintcdn.com/selll/vG17S6xpomHf6obv/logo/hanabira-by-leaf-white.png?fit=max\u0026auto=format\u0026n=vG17S6xpomHf6obv\u0026q=85\u0026s=98557e60eef0ac753ddc0bf900f8608e","href":"https://hana.leafphp.dev"},"favicon":"/favicon.png","navbar":{"links":[{"label":"Support Leaf 💚","href":"https://leafphp.dev/support.html"}]},"footer":{"socials":{"x":"https://x.com/leafphp","github":"https://github.com/leafsphp","linkedin":"https://linkedin.com/company/leafphp"},"links":[{"header":"Resources","items":[{"label":"Hire Us","href":"https://studio.leafphp.dev"},{"label":"Support Hana's development","href":"https://leafphp.dev/support"}]},{"header":"Company","items":[{"label":"Build with Leaf","href":"https://leafphp.dev"},{"label":"Blog","href":"https://blog.leafphp.dev"}]}]},"styling":{"codeblocks":{"theme":"ayu-dark"}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","cursor","vscode"]},"navigation":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/Pkrm9NJPE3"},{"anchor":"Blog","icon":"newspaper","href":"https://blog.leafphp.dev"}]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"selll","hasAudioNarration":false,"actualSubdomain":"selll","customDomains":["docs.hana.leafphp.dev"],"gitSource":{"type":"github","owner":"leafsphp","repo":"hana-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6ae93ee6f9ad977f1c31309b:success","clientVersion":"0.0.4088","searchFilterCounts":[{"language":"default","tag":"Guides","count":15},{"language":"default","tag":"Routing","count":6},{"language":"default","tag":"State Management","count":4},{"language":"default","tag":"Authentication","count":3},{"language":"default","tag":"Getting started","count":2}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"comment-mode","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[],"page":{"pagePath":"state/reducers","slug":"/state/reducers","pageMetadata":{"title":"Reducers","description":"Abstract multiple state actions into a single store function","icon":"image","href":"/state/reducers"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Abstract multiple state actions into a single store function\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,p:`p`,pre:`pre`,span:`span`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Tip,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Tip)_missingMdxReference(`Tip`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Hana allows you easily set and get your global state using the `,_jsx(_components.code,{children:`useStore()`}),` hook, and while this is super easy, it quickly gets annoying if you have to work with multiple state values, especially if they are all working towards the same feature.`]}),`\n`,_jsxs(_components.p,{children:[`Reducers allow you to abstract all that into a single function which can be called from anywhere in your app, using the `,_jsx(_components.code,{children:`useReducer()`}),` hook.`]}),`\n`,_jsx(Heading,{level:`2`,id:`defining-a-reducer`,children:`Defining a reducer`}),`\n`,_jsx(_components.p,{children:`At the core, a Hana reducer is just a function that accepts two arguments:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsx(_components.li,{children:`The current global state`}),`\n`,_jsx(_components.li,{children:`A payload passed in from when the function is called`}),`\n`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` setFromPayload`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` payload`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`) `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#5A6673`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#5A6673`,\"--shiki-dark-font-style\":`italic`},children:` \t// Perform some operations`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` \treturn`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`\t\t...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`\t\t...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`payload`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`This function returns a new application state, while allowing you to perform additional actions.`}),`\n`,_jsx(Heading,{level:`2`,id:`registering-a-reducer`,children:`Registering a reducer`}),`\n`,_jsx(_components.p,{children:`Hana reducers are registered globally so they can be used anywhere in your app without carrying over the entire function as done in other reducer implementations. In Hana, all you need is the reducer name. You can register the reducer globally using:`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`The `,_jsx(_components.code,{children:`createStore()`}),` function right on init`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`useReducer()`}),` but this can cause problems if not done right`]}),`\n`]}),`\n`,_jsxs(Heading,{level:`3`,id:`using-createstore`,children:[`Using `,_jsx(_components.code,{children:`createStore()`})]}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.code,{children:`createStore()`}),` is OPTIONALLY used to initialize your global store with default options like the initial state, reducers, modules and other items. To add reducers, you can either `,_jsx(_components.a,{href:`/state/modules`,children:`use a module`}),` or pass the reducer directly like this:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`18`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { createStore } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`createStore`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#5A6673`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#5A6673`,\"--shiki-dark-font-style\":`italic`},children:` // Other config`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` reducers`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` setItems`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` payload`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`) `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#5A6673`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#5A6673`,\"--shiki-dark-font-style\":`italic`},children:` // perform some operation`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` items `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` state`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`items`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`reverse`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`()`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` return`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` items`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`items`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`payload`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` ]`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`})`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The example above registers a reducer called `,_jsx(_components.code,{children:`setItems`}),` that reverses the order of the items in the state object and adds the payload to the end of the array. This reducer can be used in any component using the `,_jsx(_components.code,{children:`useReducer()`}),` hook, but we will get to that later.`]}),`\n`,_jsxs(Heading,{level:`3`,id:`using-usereducer`,children:[`**Using **`,_jsx(_components.code,{children:`useReducer()`})]}),`\n`,_jsx(_components.p,{children:`This hook takes in the reducer function you want to register, and uses the name of the function as the name of the reducer. This means that the name of the reducer function must be the same as the name of the reducer you want to register.`}),`\n`,_jsx(Tip,{children:_jsxs(_components.p,{children:[`We recommend using `,_jsx(_components.code,{children:`createStore()`}),` to register all your reducers instead of `,_jsx(_components.code,{children:`useReducer()`}),` because this method heavily depends on execution order. If the user calls a component that requires the reducer before it is registered, you could break your application. You should use this method to register your reducers ONLY if you can guarantee the correct execution order`]})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { useReducer } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` setItems`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` payload`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`) `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` Component`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` addToList `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useReducer`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(setItems)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` return`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#39BAE6`,\"--shiki-dark\":`#39BAE6`},children:`div`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`>`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#39BAE6`,\"--shiki-dark\":`#39BAE6`},children:`button`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` onClick`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`{`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`() `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` addToList`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`([`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'New item'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`])`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`}`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`Add to list`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`\u003c/`}),_jsx(_components.span,{style:{color:`#39BAE6`,\"--shiki-dark\":`#39BAE6`},children:`button`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`>`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:` \u003c/`}),_jsx(_components.span,{style:{color:`#39BAE6`,\"--shiki-dark\":`#39BAE6`},children:`div`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`>`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` )`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`In this case, the reducer is passed directly to `,_jsx(_components.code,{children:`useReducer()`}),` . It will take the function name which is `,_jsx(_components.code,{children:`setItems()`}),` in this case, and register it globally so you can use it in other components without needing to export the function first:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { useReducer } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` Component`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` setItems `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useReducer`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'setItems'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#5A6673`,\"--shiki-light-font-style\":`italic`,\"--shiki-dark\":`#5A6673`,\"--shiki-dark-font-style\":`italic`},children:` // items is an array of items the user wants to add to the list`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` addItemsToList`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:`items`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`) `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` setItems`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(items)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` `})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`Remember that this will only work if the component with the initial `,_jsx(_components.code,{children:`useReducer()`}),` is called first`]})}),`\n`,_jsx(Heading,{level:`2`,id:`using-a-reducer`,children:`Using a reducer`}),`\n`,_jsx(_components.p,{children:`After registering your reducer globally, the easy part is using your reducer to do all the cool magical state updates with just one function. Let’s look at an example where some data is collected from an API response and synced to state:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` [`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` setUser] `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useStore`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'user'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` [`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` setWallets] `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useStore`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'wallets'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` [`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` setRecentContacts] `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useStore`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'recentContacts'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` setDataFromResponse`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` async`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`\tconst`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` data `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` await`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` getResponse`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`()`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`\tsetUser`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`user)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`\tsetWallets`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`wallets)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`\tsetRecentContacts`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`recentContacts)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`})}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`While this isn’t too bad, our `,_jsx(_components.code,{children:`setItems()`}),` from will allow us to do this same thing in a much more elegant way:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` writeToStore `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useReducer`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'setItems'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`...`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` setDataFromResponse`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` async`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`\tconst`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` data `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` await`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` getResponse`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`()`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`\twriteToStore`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t\tuser`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`user`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t\twallets`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`wallets`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t\trecentContacts`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`recentContacts`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t})`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`})}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`While this is a super simple example and will probably not happen much in production, the idea is the same. Reducers allow you to define some actions that return a new state and are usually used for complex flows.`}),`\n`,_jsx(Heading,{level:`2`,id:`reducers-with-no-values`,children:`Reducers with no values`}),`\n`,_jsx(_components.p,{children:`Most implementations of reducers force you to pass a payload into your reducer function, but that’s totally optional with Hana. This allows you to define self-contained reducers that perform and internal action and update the state, for example, a logout action:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`13`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`13`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { createStore } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`createStore`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` reducers`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` logout`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`) `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` ({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t token`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` null`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t refreshToken`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` null`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t user`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` null`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t anythingElseToUnset`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` null`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` })`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`})`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:`And then use it like this:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`7`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`7`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { useReducer } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` LogoutButton`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` logout `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useReducer`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'logout'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` return`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:` \u003c`}),_jsx(_components.span,{style:{color:`#39BAE6`,\"--shiki-dark\":`#39BAE6`},children:`button`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` onClick`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`{`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`logout`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`}`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`Logout`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`\u003c/`}),_jsx(_components.span,{style:{color:`#39BAE6`,\"--shiki-dark\":`#39BAE6`},children:`button`}),_jsx(_components.span,{style:{color:`#39BAE680`,\"--shiki-dark\":`#39BAE680`},children:`>`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`reducers-with-async-actions`,children:`Reducers with async actions`}),`\n`,_jsx(_components.p,{children:`Hana reducers aren’t just a handy way of setting your state values, you can also use them to perform async actions like fetching values from an API:`}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`18`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`18`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { createStore } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:`createStore`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` reducers`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` addWallet`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` async`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:` payload`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`) `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` response `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` await`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` linkNewWallet`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(payload)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` return`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`state`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t\tbalance`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` response`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`balance`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t\twallets`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`:`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` [`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`\t\t ...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`state`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`wallets`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t\t response`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`data`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`.`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`wallet`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`\t\t]`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`})`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`And then you can use this `,_jsx(_components.code,{children:`addWallet()`}),` reducer to add a new wallet and update the user’s balance in one elegant line:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { useReducer } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` Component`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` addWallet `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useReducer`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'addWallet'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` addToList`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` async`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` await`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` addWallet`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`({`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`...`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`})`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`2`,id:`skip-re-rendering-ui`,children:`Skip re-rendering UI`}),`\n`,_jsxs(_components.p,{children:[`Sometimes, you may need to use a reducer in a component that does not actually re-render the UI after the reducer is called. In this case, you can use the `,_jsx(_components.code,{children:`useStaticReducer()`}),` hook. It works exactly like the `,_jsx(_components.code,{children:`useReducer()`}),` hook, but it does not cause the component to re-render when the reducer is called.`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`11`,language:`tsx`,children:_jsx(_components.pre,{className:`shiki shiki-themes ayu-dark ayu-dark`,style:{backgroundColor:`#0d1017`,\"--shiki-dark-bg\":`#0d1017`,color:`#bfbdb6`,\"--shiki-dark\":`#bfbdb6`},language:`tsx`,children:_jsxs(_components.code,{language:`tsx`,numberOfLines:`11`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`import`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` { useStaticReducer } `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`from`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:` '@hanabira/store'`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` Component`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` () `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` setItems `}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:`=`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` useStaticReducer`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(`}),_jsx(_components.span,{style:{color:`#AAD94C`,\"--shiki-dark\":`#AAD94C`},children:`'setItems'`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:` const`}),_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` addToList`}),_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` =`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` (`}),_jsx(_components.span,{style:{color:`#D2A6FF`,\"--shiki-dark\":`#D2A6FF`},children:`items`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`) `}),_jsx(_components.span,{style:{color:`#FF8F40`,\"--shiki-dark\":`#FF8F40`},children:`=>`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#FFB454`,\"--shiki-dark\":`#FFB454`},children:` setItems`}),_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`(items)`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:` }`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#F29668`,\"--shiki-dark\":`#F29668`},children:` ...`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#BFBDB6`,\"--shiki-dark\":`#BFBDB6`},children:`}`}),_jsx(_components.span,{style:{color:`#BFBDB6B3`,\"--shiki-dark\":`#BFBDB6B3`},children:`;`})]}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":"ayu-dark"},"config":{},"pageMetadata":{"title":"Reducers","description":"Abstract multiple state actions into a single store function","icon":"image","href":"/state/reducers"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Defining a reducer","slug":"defining-a-reducer","depth":2,"children":[]},{"title":"Registering a reducer","slug":"registering-a-reducer","depth":2,"children":[{"title":"Using createStore()","slug":"using-createstore","depth":3,"children":[]},{"title":"**Using **useReducer()","slug":"using-usereducer","depth":3,"children":[]}]},{"title":"Using a reducer","slug":"using-a-reducer","depth":2,"children":[]},{"title":"Reducers with no values","slug":"reducers-with-no-values","depth":2,"children":[]},{"title":"Reducers with async actions","slug":"reducers-with-async-actions","depth":2,"children":[]},{"title":"Skip re-rendering UI","slug":"skip-re-rendering-ui","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"selll","siteName":"Hana","title":"Reducers - Hana","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2025-10-15T22:30:20.192Z","originalFileLocation":"state/reducers.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Abstract multiple state actions into a single store function\">\u003cmeta data-mint-head name=\"application-name\" content=\"Hana\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Reducers - Hana\">\u003cmeta data-mint-head property=\"og:description\" content=\"Abstract multiple state actions into a single store function\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Hana\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.hana.leafphp.dev/state/reducers\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://selll.mintlify.site/_mintlify/api/og/v2?division=State+Management\u0026amp;title=Reducers\u0026amp;description=Abstract+multiple+state+actions+into+a+single+store+function\u0026amp;theme=c70e55f8fff8077799a63b0c\u0026amp;signature=dbc476e9e2ba9c2ea547d830196471029e74e3e1bc7505306815ab325d8b1dbf\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Reducers - Hana\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Abstract multiple state actions into a single store function\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://selll.mintlify.site/_mintlify/api/og/v2?division=State+Management\u0026amp;title=Reducers\u0026amp;description=Abstract+multiple+state+actions+into+a+single+store+function\u0026amp;theme=c70e55f8fff8077799a63b0c\u0026amp;signature=dbc476e9e2ba9c2ea547d830196471029e74e3e1bc7505306815ab325d8b1dbf\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/selll/9lI7CDw1qq6BaVes/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Hana\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#C391D9\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.hana.leafphp.dev/state/reducers\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/state/reducers.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.hana.leafphp.dev/#organization\",\"name\":\"Hana\",\"url\":\"https://docs.hana.leafphp.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/selll/vG17S6xpomHf6obv/logo/hanabira-by-leaf-regular.png?fit=max\u0026auto=format\u0026n=vG17S6xpomHf6obv\u0026q=85\u0026s=1d1682b7a27193710c61a64497e12a70\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.hana.leafphp.dev#website\",\"name\":\"Hana\",\"url\":\"https://docs.hana.leafphp.dev\",\"publisher\":{\"@id\":\"https://docs.hana.leafphp.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.hana.leafphp.dev/state/reducers#webpage\",\"url\":\"https://docs.hana.leafphp.dev/state/reducers\",\"name\":\"Reducers\",\"description\":\"Abstract multiple state actions into a single store function\",\"dateModified\":\"2025-10-15T22:30:20.192Z\",\"isPartOf\":{\"@id\":\"https://docs.hana.leafphp.dev#website\"},\"breadcrumb\":{\"@id\":\"https://docs.hana.leafphp.dev/state/reducers#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.hana.leafphp.dev/state/reducers#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"State Management\",\"item\":\"https://docs.hana.leafphp.dev/state/index\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Reducers\",\"item\":\"https://docs.hana.leafphp.dev/state/reducers\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.hana.leafphp.dev/state/reducers#article\",\"headline\":\"Reducers\",\"name\":\"Reducers\",\"description\":\"Abstract multiple state actions into a single store function\",\"url\":\"https://docs.hana.leafphp.dev/state/reducers\",\"mainEntityOfPage\":{\"@id\":\"https://docs.hana.leafphp.dev/state/reducers#webpage\"},\"dateModified\":\"2025-10-15T22:30:20.192Z\",\"publisher\":{\"@id\":\"https://docs.hana.leafphp.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.hana.leafphp.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Hana\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Hana","nav":{"global":{"anchors":[{"anchor":"Community","icon":"discord","href":"https://discord.gg/Pkrm9NJPE3"},{"anchor":"Blog","icon":"newspaper","href":"https://blog.leafphp.dev"}]},"tabs":[{"tab":"Guides","groups":[{"group":"Getting started","pages":[{"title":"Hana: React without overengineering","href":""},{"title":"Quickstart","href":"/quickstart"}]},{"group":"Routing","pages":[{"title":"Hana Router","icon":"water","href":"/routing/index"},{"title":"Navigating","icon":"arrow-pointer","href":"/routing/navigating"},{"title":"Dynamic Routing","icon":"asterisk","href":"/routing/dynamic"},{"title":"Router Config","icon":"gear","href":"/routing/config"},{"title":"Errors","icon":"triangle-exclamation","href":"/routing/errors"},{"title":"Layouts","icon":"table-columns","href":"/routing/layouts"}]},{"group":"State Management","pages":[{"title":"State Management","description":"Global state management without all the pain","icon":"atom","href":"/state/index"},{"title":"Reducers","icon":"image","href":"/state/reducers"},{"title":"Store Modules","description":"Single store vs atoms, which wins?","icon":"code","href":"/state/modules"},{"title":"Plugins","icon":"text-size","href":"/state/plugins"}]},{"group":"Authentication","pages":[{"title":"Authentication","icon":"recycle","href":"/auth/index"},{"title":"Higher Order Components","icon":"gear","href":"/auth/hocs"},{"title":"Hooks","icon":"book","href":"/auth/hooks"}]}]}]},"basePath":"","title":"Reducers - Hana","buildId":"dpl_DTau1J5HqS9UTgVSDwGksstFWtPa","deploymentId":"dpl_DTau1J5HqS9UTgVSDwGksstFWtPa","dynamics":[],"chunks":[]}