File tree Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Expand file tree Collapse file tree 1 file changed +29
-2
lines changed Original file line number Diff line number Diff line change 1
- import React from 'react' ;
1
+ import axios from 'axios' ;
2
+ import React , { useEffect , useState } from 'react' ;
2
3
3
4
function SuperHeroesPage ( ) {
4
- return < div > SuperHeroesPage</ div > ;
5
+ const [ isLoading , setIsLoading ] = useState ( true ) ;
6
+ const [ data , setData ] = useState ( [ ] ) ;
7
+
8
+ useEffect ( ( ) => {
9
+ axios
10
+ . get ( 'http://localhost:4000/superheroes' )
11
+ . then ( res => {
12
+ setIsLoading ( false ) ;
13
+ setData ( res . data ) ;
14
+ } )
15
+ . catch ( error => console . log ( error . message ) ) ;
16
+ } , [ ] ) ;
17
+
18
+ return (
19
+ < >
20
+ < h2 > Super Heroes Page</ h2 >
21
+ { isLoading ? (
22
+ < h3 > Heros data Loading...</ h3 >
23
+ ) : (
24
+ data . map ( hero => (
25
+ < div key = { hero . id } >
26
+ < b > { hero . name } </ b > Who's alter ego is < b > { hero . alterEgo } </ b >
27
+ </ div >
28
+ ) )
29
+ ) }
30
+ </ >
31
+ ) ;
5
32
}
6
33
7
34
export default SuperHeroesPage ;
You can’t perform that action at this time.
0 commit comments