forked from arnaud-deprez/spring-boot-react-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
52 lines (45 loc) · 1.26 KB
/
App.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
import React, {useState, useRef} from 'react';
import GreetingService from './GreetingService'
import logo from './logo.svg';
import './App.css';
const Header = () => {
return (
<header className="app-header">
<img src={logo} className="app-logo" alt="logo"/>
<h1 className="app-title">Welcome to React</h1>
</header>);
};
const GreetingMessage = ({message = {}}) => {
const {id = null, content = ''} = message;
return (
<p className="app-intro">
{`${id ? id + ': ' : ''} ${content}`}
</p>
);
};
const Greeting = ({onClick}) => {
const inputEl = useRef("");
return (
<div>
<input type="text" ref={inputEl}/>
<button onClick={() => onClick(inputEl.current.value)}>
Say Hi!
</button>
</div>
);
};
const App = () => {
const [message, setMessage] = useState("");
const greetingService = new GreetingService();
const onClick = value =>
greetingService.greetings(value)
.then(setMessage);
return (
<div className="app">
<Header/>
<Greeting onClick={onClick}/>
<GreetingMessage message={message}/>
</div>
);
};
export default App;