JotaiJotai

状態
Primitive and flexible state management for React
Home
  • Introduction
core
  • atom
  • useAtom
  • Store
  • Provider
utilities
  • Storage
  • SSR
  • Async
  • Lazy
  • Resettable
  • Family
  • Callback
  • Select
  • Split
  • Reducer
extensions
  • tRPC
  • Query
  • URQL
  • Effect
  • Immer
  • XState
  • Location
  • Cache
  • Scope
  • Optics
  • Redux
  • Relay
  • Valtio
  • Zustand
guides
  • Using store outside React
  • v2 API migration
  • TypeScript
  • Next.js
  • Gatsby
  • Remix
  • React Native
  • Debugging
  • Performance
  • Testing
  • Core internals
  • Composing atoms
  • Atoms in atom
  • Initializing state on render
  • Persistence
  • Async
  • Resettable
  • Vite
tools
  • SWC
  • Babel
  • Devtools
basics
  • Concepts
  • Comparison
  • Showcase
recipes
  • Large objects
  • Custom useAtom hooks
  • useAtomEffect
  • atomWithToggle
  • atomWithCompare
  • atomWithToggleAndStorage
  • atomWithRefresh
  • atomWithRefreshAndDefault
  • atomWithListeners
  • atomWithBroadcast
  • atomWithDebounce
  • useReduerAtom
TutorialRepositoryPackageCommunityUpdates
library by Daishi Katoart by Jessie Waters
site bycandycode alternative graphic design web development agency San Diego

JotaiJotai

状態
Primitive and flexible state management for React

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 + 1
if (action.type === 'dec') return prev - 1
throw new Error('unknown action type')
}
const countReducerAtom = atomWithReducer(0, countReducer)

useReducerAtom

See useReducerAtom recipe.

library by Daishi Katoart by Jessie Waters
site bycandycode alternative graphic design web development agency San Diego
GitHubnpm
  • Introduction
core
  • atom
  • useAtom
  • Store
  • Provider
utilities
  • Storage
  • SSR
  • Async
  • Lazy
  • Resettable
  • Family
  • Callback
  • Select
  • Split
  • Reducer
extensions
  • tRPC
  • Query
  • URQL
  • Effect
  • Immer
  • XState
  • Location
  • Cache
  • Scope
  • Optics
  • Redux
  • Relay
  • Valtio
  • Zustand
guides
  • Using store outside React
  • v2 API migration
  • TypeScript
  • Next.js
  • Gatsby
  • Remix
  • React Native
  • Debugging
  • Performance
  • Testing
  • Core internals
  • Composing atoms
  • Atoms in atom
  • Initializing state on render
  • Persistence
  • Async
  • Resettable
  • Vite
tools
  • SWC
  • Babel
  • Devtools
basics
  • Concepts
  • Comparison
  • Showcase
recipes
  • Large objects
  • Custom useAtom hooks
  • useAtomEffect
  • atomWithToggle
  • atomWithCompare
  • atomWithToggleAndStorage
  • atomWithRefresh
  • atomWithRefreshAndDefault
  • atomWithListeners
  • atomWithBroadcast
  • atomWithDebounce
  • useReduerAtom