-
Notifications
You must be signed in to change notification settings - Fork 355
/
Navbar.js
33 lines (31 loc) · 1.02 KB
/
Navbar.js
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
import React, { Component } from 'react';
import { ThemeContext } from '../contexts/ThemeContext';
import { AuthContext } from '../contexts/AuthContext';
class Navbar extends Component {
// static contextType = ThemeContext;
render() {
return (
<AuthContext>{(authContext) => (
<ThemeContext.Consumer>{(themeContext) => {
const { isAuthenticated, toggleAuth } = authContext;
const { isLightTheme, light, dark } = themeContext;
const theme = isLightTheme ? light : dark;
return (
<nav style={{ background: theme.ui, color: theme.syntax }}>
<h1>Context App</h1>
<div onClick={() => toggleAuth()}>
{ isAuthenticated ? 'Logged in' : 'Logged out' }
</div>
<ul>
<li>Home</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
)
}}</ThemeContext.Consumer>
)}</AuthContext>
);
}
}
export default Navbar;