Include type of state in useSelector hook for Redux-Typescript

PHOTO EMBED

Mon Aug 02 2021 10:13:15 GMT+0000 (UTC)

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;
content_copyCOPY

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.