Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/jotai/docs/utilities/reducer.mdx

👻 Primitive and flexible state management for React
Go to Latest
File
---title: Reducernav: 3.99keywords: reducer,action,dispatchpublished: false---
## atomWithReducer
Ref: https://github.com/pmndrs/jotai/issues/38
```jsimport { atomWithReducer } from 'jotai/utils'
const countReducer = (prev, action) => { if (action.type === 'inc') return prev + 1 if (action.type === 'dec') return prev - 1 throw new Error('unknown action type')}
const countReducerAtom = atomWithReducer(0, countReducer)```
<CodeSandbox id="g3tsx" />## useReducerAtom
See [useReducerAtom](../recipes/use-reducer-atom.mdx) recipe.