Include type of state in useSelector hook for Redux-Typescript


Mon Aug 02 2021 10:13:15 GMT+0000 (Coordinated Universal Time)

Saved by @ravviolo #react #redux #typescript #useselector

import { useSelector, TypedUseSelectorHook } from "react-redux";
// Import type of state 
// Import {RootState} from '../store'

export const useTypedSelector: TypedUseSelectorHook<RootState> = useSelector;

In react-redux app using typescript when trying to get global state using useSelector hook it typescript complains on not knowing the type of the state. Use custom useTypedSelector hook to comfort typescript.