useSelector

function
react/src/hooks/hooks.ts:112
signature
useSelector<S, T>(selector, isEqual): T

Selects a derived value from the store using an external-store subscription. Re-renders when the selected value changes per isEqual.

Type parameters

NameTypeDescription
Sextends Record<any, any>State type returned by getState().
TSelected value type.

Parameters

NameTypeDescription
selector(state: DeepReadonly<S>) => T(state) => value derived from the current state.
NameTypeDescription
isEqual(a: T, b: T) => booleanOptional equality comparator (defaults to Object.is).

Returns

T

Example

example
const total = useSelector((s: AppState) => s.todos.items.length);