React · Junior · Question 45 of 75
What are useSelector and useDispatch for?
- ✓Correct answer:
useSelectorreads data from the store,useDispatchgives youdispatch - 2
useSelectorfinds a DOM element,useDispatchfires a DOM event - 3Both hooks create a separate local store for the component
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.