useSelector(selector[, equalityFn])
React Hook for accessing the Selector result.
Arguments
selector: Selector
- a selector function created withcreateSelector
.equalityFn?: (a: unknown, b: unknown) => boolean
- the function for checking that new result value ofSelector
equals the old value. For more info: useMappedState
Returns
{object}
- the object returned by Selector
.
Example
Full example: createSelector
// components/TodoList.tsx
function TodoList() {
// use your selector with useSelector
const todos = useSelector(getTodos);
return (
<div>
{todos.map(todo => (
<Todo todo={todo} key={todo.id} />
))}
</div>
);
}