UNPKG

jotai

Version:

👻 Primitive and flexible state management for React

14 lines (13 loc) • 615 B
'use client'; import { useCallback } from 'react'; import { useAtom } from '../../react.js'; export function useReducerAtom(anAtom, reducer, options) { if (process.env.NODE_ENV !== 'production') { console.warn('[DEPRECATED] useReducerAtom is deprecated and will be removed in the future. Please create your own version using the recipe. https://github.com/pmndrs/jotai/pull/2467'); } const [state, setState] = useAtom(anAtom, options); const dispatch = useCallback((action) => { setState((prev) => reducer(prev, action)); }, [setState, reducer]); return [state, dispatch]; }