React · Junior · Question 45 of 75

What are useSelector and useDispatch for?

Explanation

const todos = useSelector(state => state.todos) re-renders the component only if the selector result changed (by reference). const dispatch = useDispatch(); dispatch(added(todo)). TypeScript projects create typed versions useAppSelector and useAppDispatch.

Further reading

Problem with a question

React · Junior · question 45

Test yourself

Take the React · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz