forked from keaaa/radix-example-workshop-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
47 lines (39 loc) · 990 Bytes
/
App.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import React from "react";
import Echo from "./components/Echo";
import Header from "./components/Header";
import EchoService from "./services/Echo";
import "./App.css";
class App extends React.Component {
constructor() {
super();
this.refreshInterval = 1000;
this.useMockData = false;
this.state = {
echoResult: {},
nrRefresh: 0,
};
}
componentDidMount() {
setInterval(this.loadData, this.refreshInterval);
}
loadData = () => {
const echoService = EchoService(this.useMockData);
const nrRefresh = this.state.nrRefresh + 1;
echoService
.fetch("/api/echo")
.then(data => this.setState({ echoResult: data, nrRefresh: nrRefresh }));
};
render() {
return (
<div className="App">
<Header />
<Echo
result={this.state.echoResult}
refreshInterval={this.refreshInterval}
nrRefresh={this.state.nrRefresh}
/>
</div>
);
}
}
export default App;