Skip to content

Latest commit

 

History

History
19 lines (14 loc) · 398 Bytes

atom-with-reducer.mdx

File metadata and controls

19 lines (14 loc) · 398 Bytes
title
atomWithReducer

Ref: pmndrs#38

import { 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)