Skip to content

Instantly share code, notes, and snippets.

@ChaseH88
Created May 10, 2022 08:44
Show Gist options
  • Save ChaseH88/4bb57b8d43c75deecafc2601ed3f0838 to your computer and use it in GitHub Desktop.
Save ChaseH88/4bb57b8d43c75deecafc2601ed3f0838 to your computer and use it in GitHub Desktop.
This hook will get you the global app state using Redux
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