Search code examples
reactjstypescriptreduxredux-toolkitreact-typescript

using IRootState type in useSelector


I use IRootState type for useSelector in redux-toolkit (typeScript) like this :

    const usersPage = useSelector<IRootState, number>((state) => state.users.page)

I saw this code in this link in stackoverflow !

But now my question is from where I can import this type !? or more ! I have to make this or import this ?


Solution

  • You have to define that type yourself, see here in the docs: https://redux-toolkit.js.org/usage/usage-with-typescript#getting-the-state-type