State Management · Middle · Question 16 of 75
How do you type useSelector and useDispatch in a TypeScript project?
- ✓Correct answer: Infer
RootState/AppDispatchfrom the store and createuseAppSelector/useAppDispatch - 2Write the entire state interface by hand and cast every selector
- 3Type them as
any- RTK can't be typed
Explanation
type RootState = ReturnType<typeof store.getState>, type AppDispatch = typeof store.dispatch, then useSelector.withTypes<RootState>(). Types follow the reducers automatically.