-
Notifications
You must be signed in to change notification settings - Fork 40
/
Fetch data from Github Repository in React js
53 lines (50 loc) · 1.58 KB
/
Fetch data from Github Repository in React js
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
53
import React, { useState, useEffect} from "react";
import { Container } from "react-bootstrap";
function Fetchdatafromgithub() {
const [userData, setUserdata]= useState([]);
useEffect( ()=>{
const getUserdata= async()=>{
const reqData= await fetch("https://raw.githubusercontent.com/devopsdeveloper1107/jsonfile/main/userData");
const resData= await reqData.json();
//console.log(resData);
setUserdata(resData);
}
getUserdata();
},[]);
return(
<React.Fragment>
<Container>
<div className="row fthight">
<div className="col-md-10 mb-3 mt-3">
<h3 className='mt-3 mb-4'>Fetch data from Github Repository in React js</h3>
<table className="table">
<thead>
<tr>
<th>Sr. No</th>
<th>User Name</th>
<th>Email</th>
<th>Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{
userData.map( (getusers, index)=>(
<tr key={index}>
<td>{index+1 } </td>
<td>{ getusers.user_name } </td>
<td>{ getusers.user_email } </td>
<td>{ getusers.user_address} </td>
<td><button className="btn btn-danger">Delete</button></td>
</tr>
))
}
</tbody>
</table>
</div>
</div>
</Container>
</React.Fragment>
);
}
export default Fetchdatafromgithub;