|
1 |
| -import React, {useEffect, useState} from 'react'; |
| 1 | +import React, {ReactElement, useEffect, useState} from 'react'; |
2 | 2 | import logo from '../logo.svg';
|
3 | 3 | import './App.css';
|
4 | 4 | import {callBackendHealth} from "../api";
|
5 | 5 |
|
6 |
| -function App() { |
7 |
| - const[test,setTest] = useState("test"); |
| 6 | +function App():ReactElement { |
| 7 | + const [backendLiveTime, setBackendLiveTime] = useState<number | string>("Init"); |
8 | 8 |
|
9 |
| - useEffect(() => { |
10 |
| - Promise.all([callBackendHealth()]) |
11 |
| - .then(([backendHealthData]) => { |
12 |
| - setTest(backendHealthData.uptimeInSeconds) |
13 |
| - }) |
14 |
| - }, [test]); |
| 9 | + useEffect(() => { |
| 10 | + updateVariables() |
| 11 | + }); |
15 | 12 |
|
16 |
| - return ( |
17 |
| - <div className="App"> |
18 |
| - <header className="App-header"> |
19 |
| - <p> |
20 |
| - Hello World |
21 |
| - </p> |
22 |
| - <img src={logo} className="App-logo" alt="logo" /> |
23 |
| - <p> |
24 |
| - Edit <code>src/App.tsx</code> and save to reload. |
25 |
| - </p> |
26 |
| - <a |
27 |
| - className="App-link" |
28 |
| - href="https://reactjs.org" |
29 |
| - target="_blank" |
30 |
| - rel="noopener noreferrer" |
31 |
| - > |
32 |
| - Learn React |
33 |
| - </a> |
34 |
| - <button onClick={() => setTest(callBackendHealth().data)}>Test</button> |
35 |
| - <p>{test}</p> |
36 |
| - </header> |
37 |
| - </div> |
38 |
| - ); |
| 13 | + function updateVariables(): void { |
| 14 | + Promise.all([callBackendHealth()]) |
| 15 | + .then(([backendHealthData]) => { |
| 16 | + setBackendLiveTime(backendHealthData.uptimeInSeconds) |
| 17 | + }) |
| 18 | + } |
| 19 | + |
| 20 | + return ( |
| 21 | + <div className="App"> |
| 22 | + <header className="App-header"> |
| 23 | + <p> |
| 24 | + Hello World |
| 25 | + </p> |
| 26 | + <img src={logo} className="App-logo" alt="logo"/> |
| 27 | + <p> |
| 28 | + Edit <code>src/App.tsx</code> and save to reload. |
| 29 | + </p> |
| 30 | + <a |
| 31 | + className="App-link" |
| 32 | + href="https://reactjs.org" |
| 33 | + target="_blank" |
| 34 | + rel="noopener noreferrer" |
| 35 | + > |
| 36 | + Learn React |
| 37 | + </a> |
| 38 | + <button style={{marginTop: "20px"}} onClick={() => updateVariables()}>Test</button> |
| 39 | + <p>{backendLiveTime}</p> |
| 40 | + </header> |
| 41 | + </div> |
| 42 | + ); |
39 | 43 | }
|
40 | 44 |
|
41 | 45 | export default App;
|
0 commit comments