Skip to content

Commit 477c3a2

Browse files
author
Satish Yadav
committed
code moved to superhero component
1 parent a62df69 commit 477c3a2

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed
Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1-
import React from 'react';
1+
import axios from 'axios';
2+
import React, { useEffect, useState } from 'react';
23

34
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+
);
532
}
633

734
export default SuperHeroesPage;

0 commit comments

Comments
 (0)