Skip to content

Commit 85598d2

Browse files
committed
Code for 2-index
1 parent c3d23ad commit 85598d2

File tree

4 files changed

+28
-35
lines changed

4 files changed

+28
-35
lines changed

app/components/Battle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Link } from 'react-router-dom'
88
function Instructions () {
99
return (
1010
<ThemeConsumer>
11-
{({ theme }) => (
11+
{(theme) => (
1212
<div className='instructions-container'>
1313
<h1 className='center-text header-lg'>
1414
Instructions
@@ -50,7 +50,7 @@ class PlayerInput extends React.Component {
5050
render() {
5151
return (
5252
<ThemeConsumer>
53-
{({ theme }) => (
53+
{(theme) => (
5454
<form className='column player' onSubmit={this.handleSubmit}>
5555
<label htmlFor='username' className='player-label'>
5656
{this.props.label}
@@ -88,7 +88,7 @@ PlayerInput.propTypes = {
8888
function PlayerPreview ({ username, onReset, label }) {
8989
return (
9090
<ThemeConsumer>
91-
{({ theme }) => (
91+
{(theme) => (
9292
<div className='column player'>
9393
<h3 className='player-label'>{label}</h3>
9494
<div className={`row bg-${theme}`}>

app/components/Card.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ThemeConsumer } from '../contexts/theme'
55
export default function Card ({ header, subheader, avatar, href, name, children }) {
66
return (
77
<ThemeConsumer>
8-
{({ theme }) => (
8+
{(theme) => (
99
<div className={`card bg-${theme}`}>
1010
<h4 className='header-lg center-text'>
1111
{header}

app/components/Nav.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const activeStyle = {
66
color: 'rgb(187, 46, 31)'
77
}
88

9-
export default function Nav () {
9+
export default function Nav ({ toggleTheme }) {
1010
return (
1111
<ThemeConsumer>
12-
{({ theme, toggleTheme }) => (
12+
{(theme) => (
1313
<nav className='row space-between'>
1414
<ul className='row nav'>
1515
<li>

app/index.js

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,30 @@ const Popular = React.lazy(() => import('./components/Popular'))
1010
const Battle = React.lazy(() => import('./components/Battle'))
1111
const Results = React.lazy(() => import('./components/Results'))
1212

13-
class App extends React.Component {
14-
state = {
15-
theme: 'light',
16-
toggleTheme: () => {
17-
this.setState(({ theme }) => ({
18-
theme: theme === 'light' ? 'dark' : 'light'
19-
}))
20-
}
21-
}
22-
render() {
23-
return (
24-
<Router>
25-
<ThemeProvider value={this.state}>
26-
<div className={this.state.theme}>
27-
<div className='container'>
28-
<Nav />
13+
function App () {
14+
const [theme, setTheme] = React.useState('light')
15+
const toggleTheme = () => setTheme((theme) => theme === 'light' ? 'dark' : 'light')
2916

30-
<React.Suspense fallback={<Loading />} >
31-
<Switch>
32-
<Route exact path='/' component={Popular} />
33-
<Route exact path='/battle' component={Battle} />
34-
<Route path='/battle/results' component={Results} />
35-
<Route render={() => <h1>404</h1>} />
36-
</Switch>
37-
</React.Suspense>
38-
</div>
17+
return (
18+
<Router>
19+
<ThemeProvider value={theme}>
20+
<div className={theme}>
21+
<div className='container'>
22+
<Nav toggleTheme={toggleTheme} />
23+
24+
<React.Suspense fallback={<Loading />} >
25+
<Switch>
26+
<Route exact path='/' component={Popular} />
27+
<Route exact path='/battle' component={Battle} />
28+
<Route path='/battle/results' component={Results} />
29+
<Route render={() => <h1>404</h1>} />
30+
</Switch>
31+
</React.Suspense>
3932
</div>
40-
</ThemeProvider>
41-
</Router>
42-
)
43-
}
33+
</div>
34+
</ThemeProvider>
35+
</Router>
36+
)
4437
}
4538

4639
ReactDOM.render(

0 commit comments

Comments
 (0)