File tree 1 file changed +34
-18
lines changed
1 file changed +34
-18
lines changed Original file line number Diff line number Diff line change 1
1
import logo from './logo.svg' ;
2
2
import './App.css' ;
3
+ import { useEffect , useState } from "react" ;
3
4
4
5
function App ( ) {
5
- return (
6
- < div className = "App" >
7
- < header className = "App-header" >
8
- < img src = { logo } className = "App-logo" alt = "logo" />
9
- < p >
10
- Edit < code > src/App.js</ code > and save to reload.
11
- </ p >
12
- < a
13
- className = "App-link"
14
- href = "https://reactjs.org"
15
- target = "_blank"
16
- rel = "noopener noreferrer"
17
- >
18
- Learn React
19
- </ a >
20
- </ header >
21
- </ div >
22
- ) ;
6
+ const [ message , setMessage ] = useState ( [ ] ) ;
7
+
8
+ useEffect ( ( ) => {
9
+ fetch ( "/hello" )
10
+ . then ( ( response ) => {
11
+ return response . json ( ) ;
12
+ } )
13
+ . then ( function ( data ) {
14
+ setMessage ( data ) ;
15
+ } ) ;
16
+ } , [ ] ) ;
17
+
18
+ return (
19
+ < div className = "App" >
20
+ < header className = "App-header" >
21
+ < img src = { logo } className = "App-logo" alt = "logo" />
22
+ < p >
23
+ Edit < code > src/App.js</ code > and save to reload.
24
+ </ p >
25
+ < a
26
+ className = "App-link"
27
+ href = "https://reactjs.org"
28
+ target = "_blank"
29
+ rel = "noopener noreferrer"
30
+ >
31
+ Learn React
32
+ </ a >
33
+ < ul >
34
+ { message . map ( ( text , index ) => < li key = { `${ index } -${ text } ` } > { text } </ li > ) }
35
+ </ ul >
36
+ </ header >
37
+ </ div >
38
+ ) ;
23
39
}
24
40
25
41
export default App ;
You can’t perform that action at this time.
0 commit comments