-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathApp.tsx
43 lines (40 loc) · 952 Bytes
/
App.tsx
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
import React, { useEffect, useState } from "react";
import logo from "./logo.svg";
import "./App.css";
type Greeting = {
id: number;
name: string;
};
function App() {
const [greeting, setGreeting] = useState<Greeting>();
useEffect(() => {
fetch("/api")
.then(res => res.json())
.then(setGreeting)
.catch(console.error);
}, [setGreeting]);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
{greeting ? (
<p>Hello from {greeting.name}</p>
) : (
<p>Loading...</p>
)}
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;