JotaiJotai

상태
React를 위한 기본적이고 유연한 상태 관리

Reducer

atomWithReducer

참조: https://github.com/pmndrs/jotai/issues/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)

Stackblitz

useReducerAtom

useReducerAtom 레시피를 참고하세요.