Created
May 10, 2022 08:44
-
-
Save ChaseH88/4bb57b8d43c75deecafc2601ed3f0838 to your computer and use it in GitHub Desktop.
This hook will get you the global app state using Redux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useSelector } from 'react-redux'; | |
import { RootState } from '../state'; | |
type States = keyof RootState; | |
/** | |
* This hook will get you the global app state | |
* @returns App State | |
* @param stateName | |
*/ | |
const useAppState = <S extends States>(stateName: S): RootState[S] => | |
useSelector( | |
(state: RootState) => state[stateName] as unknown as RootState[S] | |
); | |
export { useAppState }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment