Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Go to Latest
function useReducer
import { useReducer } from "https://deno.land/x/fathym_atomic_design_kit@v0.0.117/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