State Management · Middle · Question 16 of 75

How do you type useSelector and useDispatch in a TypeScript project?

Explanation

type RootState = ReturnType<typeof store.getState>, type AppDispatch = typeof store.dispatch, then useSelector.withTypes<RootState>(). Types follow the reducers automatically.

Further reading

Problem with a question

State Management · Middle · question 16

Test yourself

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

Take this quiz