useSelector
functionsignature
useSelector<S, T>(selector, isEqual): TSelects a derived value from the store using an external-store subscription.
Re-renders when the selected value changes per isEqual.
Type parameters
| Name | Type | Description |
|---|---|---|
S | extends Record<any, any> | State type returned by getState(). |
T | — | Selected value type. |
Parameters
| Name | Type | Description |
|---|---|---|
selector | (state: DeepReadonly<S>) => T | (state) => value derived from the current state. |
| Name | Type | Description |
|---|---|---|
isEqual | (a: T, b: T) => boolean | Optional equality comparator (defaults to Object.is). |
Returns
T
Example
example
const total = useSelector((s: AppState) => s.todos.items.length);