I came across useAppSelector while using redux with RTK query. So what will be the difference between useSelector and useAppSelector gonna be or both works in the same way?
Asked
Active
Viewed 2,037 times
1 Answers
6
On a runtime level, they are 100% equal. The difference is that one is untyped so the state
variable is unknown
and needs to be manually typed by you on every single call of useSelector
- and you can pass in everything wrong there without causing an error.
useAppSelector
on the other hand gets declared with your RootState
in one place and after that it's typesafe, ready to be used everywhere in your application.

phry
- 35,762
- 5
- 67
- 81
-
2That is why useAppSelector and useAppDispatch is recommended to be used with TypeScript. – Anshik gupta Aug 15 '22 at 15:16
-
1so useApp* is for typescript & useSelector/useDispatch is for plainJS? – user3606183 Dec 30 '22 at 00:54
-
Yes, TypeScript needs some extra information, so you have to create those custom-typed hooks. – phry Dec 30 '22 at 08:56