-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.jsx
64 lines (56 loc) · 1.19 KB
/
script.jsx
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
54
55
56
57
58
59
60
61
62
63
64
class App extends React.Component {
constructor(props) {
super(props);
this.state = { city: 'vienna' };
}
selectCity = evt => {
const newValue = evt.target.value;
// this.setState({
// city: newValue
// });
this.setState(state => {
if (state.city === newValue) {
return null;
}
return {
city: newValue
};
});
};
render() {
return (
<div>
<button type="button" value="vienna" onClick={this.selectCity}>
Vienna
</button>
<button type="button" value="paris" onClick={this.selectCity}>
pari
</button>
</div>
);
}
}
class City extends React.Component {
constructor(props) {
super(props);
this.state = { loading: true };
setTimeout(() => {
this.setState({ loading: false });
}, 1000);
}
componentWillReceiveProps() {
this.setState({ loading: true });
setTimeout(() => {
this.setState({ loading: false });
}, 1000);
}
render() {
if (this.state.loading) {
return (
<img src={`/spinner.gif`} alt="loading" />
);
}
c
}
}
ReactDOM.render(<App />, document.getElementById("root"));