Skip to main content
Deno 2 is finally here 🎉️
Learn more
Go to Latest
function useReducer
import { useReducer } from "https://deno.land/x/fathym_atomic_design_kit@v0.0.114/src/src.deps.ts";

An alternative to useState.

useReducer is usually preferable to useState when you have complex state logic that involves multiple sub-values. It also lets you optimize performance for components that trigger deep updates because you can pass dispatch down instead of callbacks.

Parameters

reducer: Reducer<S, A>

Given the current state and an action, returns the new state

initialState: S

The initial value to store as state

An alternative to useState.

useReducer is usually preferable to useState when you have complex state logic that involves multiple sub-values. It also lets you optimize performance for components that trigger deep updates because you can pass dispatch down instead of callbacks.

Parameters

reducer: Reducer<S, A>

Given the current state and an action, returns the new state

initialArg: I

The initial argument to pass to the init function

init: (arg: I) => S

A function that, given the initialArg, returns the initial value to store as state