-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppContext.js
More file actions
30 lines (25 loc) · 961 Bytes
/
AppContext.js
File metadata and controls
30 lines (25 loc) · 961 Bytes
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
import { getInfoOnstartUp } from './constant/Helpers';
import * as React from 'react';
import { getUniqueId } from './constant/Helpers';
const AppContext = React.createContext();
export function AppProvider({ children }) {
const [usesLeft, setUsesLeft] = React.useState(null);
const [isPremium, setIsPremium] = React.useState(null);
const [clientId, setClientId] = React.useState(null);
React.useLayoutEffect(() => {
async function onStartUp(){
const idClient = await getUniqueId();
const [uses, is_premium] = await getInfoOnstartUp(idClient);
setClientId(idClient);
setIsPremium(is_premium);
setUsesLeft(uses);
}
onStartUp();
}, [])
return (
<AppContext.Provider value={{ usesLeft, setUsesLeft, isPremium, setIsPremium }}>
{children}
</AppContext.Provider>
);
};
export const useAppContext = () => React.useContext(AppContext);