TypeScript · Middle · Question 21 of 75

How do you type Redux Toolkit hooks in a TypeScript app?

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.

Further reading

Problem with a question

TypeScript · Middle · question 21

Test yourself

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

Take this quiz