Reducer
atomWithReducer
Ref: https://github.com/pmndrs/jotai/issues/38
import { atomWithReducer } from 'jotai/utils'const countReducer = (prev, action) => {if (action.type === 'inc') return prev + 1if (action.type === 'dec') return prev - 1throw new Error('unknown action type')}const countReducerAtom = atomWithReducer(0, countReducer)
Stackblitz
useReducerAtom
See useReducerAtom recipe.