Skip to content

Commit ec13264

Browse files
committed
20-class-fields
1 parent d79b165 commit ec13264

File tree

6 files changed

+46
-91
lines changed

6 files changed

+46
-91
lines changed

app/components/Battle.jsx

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,19 @@ function Instructions() {
1717
}
1818

1919
class PlayerInput extends React.Component {
20-
constructor(props) {
21-
super(props);
22-
23-
this.state = {
24-
username: "",
25-
};
26-
27-
this.handleSubmit = this.handleSubmit.bind(this);
28-
this.handleChange = this.handleChange.bind(this);
29-
}
30-
handleSubmit(event) {
20+
state = {
21+
username: "",
22+
};
23+
handleSubmit = (event) => {
3124
event.preventDefault();
3225

3326
this.props.onSubmit(this.state.username);
34-
}
35-
handleChange(event) {
27+
};
28+
handleChange = (event) => {
3629
this.setState({
3730
username: event.target.value,
3831
});
39-
}
32+
};
4033
render() {
4134
return (
4235
<form className="card" onSubmit={this.handleSubmit}>
@@ -97,27 +90,20 @@ PlayerPreview.propTypes = {
9790
};
9891

9992
export default class Battle extends React.Component {
100-
constructor(props) {
101-
super(props);
102-
103-
this.state = {
104-
playerOne: null,
105-
playerTwo: null,
106-
};
107-
108-
this.handleSubmit = this.handleSubmit.bind(this);
109-
this.handleReset = this.handleReset.bind(this);
110-
}
111-
handleSubmit(id, player) {
93+
state = {
94+
playerOne: null,
95+
playerTwo: null,
96+
};
97+
handleSubmit = (id, player) => {
11298
this.setState({
11399
[id]: player,
114100
});
115-
}
116-
handleReset(id) {
101+
};
102+
handleReset = (id) => {
117103
this.setState({
118104
[id]: null,
119105
});
120-
}
106+
};
121107
render() {
122108
const { playerOne, playerTwo } = this.state;
123109
const disabled = !playerOne || !playerTwo;

app/components/Hover.jsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import * as React from "react";
22

33
export default class Hover extends React.Component {
4-
constructor(props) {
5-
super(props);
6-
7-
this.state = {
8-
hovering: false,
9-
};
10-
11-
this.mouseOver = this.mouseOver.bind(this);
12-
this.mouseOut = this.mouseOut.bind(this);
13-
}
14-
mouseOver() {
4+
state = {
5+
hovering: false,
6+
};
7+
mouseOver = () => {
158
this.setState({ hovering: true });
16-
}
17-
mouseOut() {
9+
};
10+
mouseOut = () => {
1811
this.setState({ hovering: false });
19-
}
12+
};
2013
render() {
2114
return (
2215
<div onMouseOver={this.mouseOver} onMouseOut={this.mouseOut}>

app/components/Loading.jsx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@ const styles = {
1111
};
1212

1313
class Delayed extends React.Component {
14-
constructor(props) {
15-
super(props);
16-
17-
this.state = {
18-
show: false,
19-
};
20-
}
14+
state = {
15+
show: false,
16+
};
2117
componentDidMount() {
2218
this.timeout = window.setTimeout(() => {
2319
this.setState({ show: true });
@@ -41,13 +37,9 @@ Delayed.propTypes = {
4137
};
4238

4339
export default class Loading extends React.Component {
44-
constructor(props) {
45-
super(props);
46-
47-
this.state = {
48-
content: props.text,
49-
};
50-
}
40+
state = {
41+
content: this.props.text,
42+
};
5143
componentDidMount() {
5244
const { speed, text } = this.props;
5345

app/components/Popular.jsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,15 @@ LanguagesNav.propTypes = {
2626
};
2727

2828
export default class Popular extends React.Component {
29-
constructor(props) {
30-
super(props);
31-
32-
this.state = {
33-
selectedLanguage: "All",
34-
repos: null,
35-
error: null,
36-
};
37-
38-
this.updateLanguage = this.updateLanguage.bind(this);
39-
}
29+
state = {
30+
selectedLanguage: "All",
31+
repos: null,
32+
error: null,
33+
};
4034
componentDidMount() {
4135
this.updateLanguage(this.state.selectedLanguage);
4236
}
43-
updateLanguage(selectedLanguage) {
37+
updateLanguage = (selectedLanguage) => {
4438
this.setState({
4539
selectedLanguage,
4640
error: null,
@@ -60,7 +54,7 @@ export default class Popular extends React.Component {
6054
error: `There was an error fetching the repositories`,
6155
});
6256
});
63-
}
57+
};
6458
render() {
6559
const { selectedLanguage, repos, error } = this.state;
6660

app/components/Results.jsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,12 @@ Card.propTypes = {
6767
};
6868

6969
class Results extends React.Component {
70-
constructor(props) {
71-
super(props);
72-
73-
this.state = {
74-
winner: null,
75-
loser: null,
76-
error: null,
77-
loading: true,
78-
};
79-
}
70+
state = {
71+
winner: null,
72+
loser: null,
73+
error: null,
74+
loading: true,
75+
};
8076
componentDidMount() {
8177
const sp = this.props.router.searchParams;
8278
const playerOne = sp.get("playerOne");

app/index.jsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ import Nav from "./components/Nav";
88
import Results from "./components/Results";
99

1010
class App extends React.Component {
11-
constructor(prop) {
12-
super(prop);
13-
14-
this.state = {
15-
theme: "light",
16-
};
17-
18-
this.toggleTheme = this.toggleTheme.bind(this);
19-
}
20-
toggleTheme() {
11+
state = {
12+
theme: "light",
13+
};
14+
toggleTheme = () => {
2115
this.setState(({ theme }) => ({
2216
theme: theme === "light" ? "dark" : "light",
2317
}));
24-
}
18+
};
2519
render() {
2620
return (
2721
<Router>

0 commit comments

Comments
 (0)