-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUseEffect
More file actions
39 lines (37 loc) · 910 Bytes
/
UseEffect
File metadata and controls
39 lines (37 loc) · 910 Bytes
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
import React, { useEffect, useState } from "react";
import axios from "axios";
const UseEffect = () => {
const [arr, setArr] = useState([]);
useEffect(() => {
axios.get("https://jsonplaceholder.typicode.com/posts").then((res) => {
setArr(res.data);
});
});
return (
<div className="container">
<table className="table">
<thead>
<tr>
<th>User id</th>
<th>id</th>
<th>Title</th>
<th>Body</th>
</tr>
</thead>
<tbody>
{arr.map((items, index) => {
return (
<tr key={index}>
<td>{items.userId}</td>
<td>{items.id}</td>
<td>{items.title}</td>
<td>{items.body}</td>
</tr>
);
})}
</tbody>
</table>
</div>
);
};
export default UseEffect;