-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserClass.js
41 lines (37 loc) · 961 Bytes
/
UserClass.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
import React from "react";
class UserClass extends React.Component {
constructor(props) {
super(props);
this.state = {
userInfo: {
name: "Dummy",
location: "Default",
},
};
console.log("Constructor");
}
async componentDidMount() {
// API call to fetch user data
const data = await fetch("https://api.github.com/users/punitsharma32112");
const json = await data.json();
this.setState({
userInfo: json,
});
console.log(json);
}
componentDidUpdate(){
console.log("component did update");
}
render() {
const { name, location, avatar_url } = this.state.userInfo;
return (
<div className="user-card">
<img src={avatar_url} alt={`${name}'s avatar`} />
<h2>Name: {name}</h2>
<h3>Location: {location}</h3>
<h4>Contact: @punit091</h4>
</div>
);
}
}
export default UserClass;