-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
53 lines (41 loc) · 1.18 KB
/
App.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from 'react';
import RootStack from './src/nav/RootStack';
export const lightTheme = {
backgroundColor: '#fff',
color: '#000'
}
export const darkTheme = {
backgroundColor: '#000',
color: '#fff'
}
const initUserInfo = {
name: 'Nguyen van A',
age: '20',
address: 'Ha Noi'
}
const initThemeContext = {
theme: lightTheme,
setTheme: (newValue: { backgroundColor: string, color: string }) => { }
}
export const UserContext = React.createContext({
userInfo: initUserInfo,
setUserInfo: (newValue: { name: string, age: string, address: string }) => { },
});
export const ThemeContext = React.createContext(initThemeContext)
const App = () => {
const [userInfo, setUserInfo] = React.useState(initUserInfo);
const [theme, setTheme] = React.useState(lightTheme);
const valueUserContext = React.useMemo(
() => ({ userInfo, setUserInfo }),
[userInfo],
);
const valueThemeContext = React.useMemo(() => ({ theme, setTheme }), [theme]);
return (
<UserContext.Provider value={valueUserContext}>
<ThemeContext.Provider value={valueThemeContext}>
<RootStack />
</ThemeContext.Provider>
</UserContext.Provider>
);
};
export default App;