TypeScript · Middle · Question 21 of 75
How do you type Redux Toolkit hooks in a TypeScript app?
- ✓Correct answer: Infer
RootStateandAppDispatchfrom the store and createuseAppSelector/useAppDispatch - 2Type every
useSelectorcall asany - 3Describe the whole state interface by hand and update it on every change
Explanation
type RootState = ReturnType<typeof store.getState> and type AppDispatch = typeof store.dispatch. Then export const useAppSelector = useSelector.withTypes<RootState>(). Types are inferred from the reducers; no manual description is needed.