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?
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.