-
Notifications
You must be signed in to change notification settings - Fork 3k
/
SplashScreenStateContext.tsx
34 lines (28 loc) · 1.28 KB
/
SplashScreenStateContext.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import React, {useContext, useMemo, useState} from 'react';
import type {ValueOf} from 'type-fest';
import CONST from './CONST';
import type ChildrenProps from './types/utils/ChildrenProps';
type SplashScreenStateContextType = {
splashScreenState: ValueOf<typeof CONST.BOOT_SPLASH_STATE>;
setSplashScreenState: React.Dispatch<React.SetStateAction<ValueOf<typeof CONST.BOOT_SPLASH_STATE>>>;
};
const SplashScreenStateContext = React.createContext<SplashScreenStateContextType>({
splashScreenState: CONST.BOOT_SPLASH_STATE.VISIBLE,
setSplashScreenState: () => {},
});
function SplashScreenStateContextProvider({children}: ChildrenProps) {
const [splashScreenState, setSplashScreenState] = useState<ValueOf<typeof CONST.BOOT_SPLASH_STATE>>(CONST.BOOT_SPLASH_STATE.VISIBLE);
const splashScreenStateContext = useMemo(
() => ({
splashScreenState,
setSplashScreenState,
}),
[splashScreenState],
);
return <SplashScreenStateContext.Provider value={splashScreenStateContext}>{children}</SplashScreenStateContext.Provider>;
}
function useSplashScreenStateContext() {
return useContext(SplashScreenStateContext);
}
export default SplashScreenStateContext;
export {SplashScreenStateContextProvider, useSplashScreenStateContext};