Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

useReducer

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.

function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, Dispatch<A>];
function useReducer<S, A, I>(
reducer: Reducer<S, A>,
initialArg: I,
init: (arg: I) => S,
): [S, Dispatch<A>];
§
useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, Dispatch<A>]
[src]

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.

§Type Parameters

§Parameters

§
reducer: Reducer<S, A>
[src]

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

§
initialState: S
[src]

The initial value to store as state

§Return Type

§
useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, Dispatch<A>]
[src]

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.

§Type Parameters

§Parameters

§
reducer: Reducer<S, A>
[src]

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

§
initialArg: I
[src]

The initial argument to pass to the init function

§
init: (arg: I) => S
[src]

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

§Return Type