showing results for - "usecontext hook"
Jonathan
20 Oct 2017
1const themes = {
2  light: {
3    foreground: "#000000",
4    background: "#eeeeee"
5  },
6  dark: {
7    foreground: "#ffffff",
8    background: "#222222"
9  }
10};
11
12const ThemeContext = React.createContext(themes.light);
13
14function App() {
15  return (
16    <ThemeContext.Provider value={themes.dark}>
17      <Toolbar />
18    </ThemeContext.Provider>
19  );
20}
21
22function Toolbar(props) {
23  return (
24    <div>
25      <ThemedButton />
26    </div>
27  );
28}
29
30function ThemedButton() {
31  const theme = useContext(ThemeContext);
32  return (
33    <button style={{ background: theme.background, color: theme.foreground }}>
34      I am styled by theme context!
35    </button>
36  );
37}