Created
October 27, 2020 15:59
-
-
Save Karnak19/ca43bf1bb4a274e990f4a725ce05d88b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable react/prefer-stateless-function */ | |
import { Component } from 'react'; | |
import './App.css'; | |
import User from './User'; | |
const apiUrl = 'https://reqres.in/api'; | |
class App extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
users: [], | |
}; | |
} | |
componentDidMount() { | |
fetch(`${apiUrl}/users`) | |
.then((res) => res.json()) | |
.then((res) => { | |
this.setState({ | |
users: res.data, | |
}); | |
}); | |
} | |
render() { | |
const { users } = this.state; | |
return ( | |
<main className="container"> | |
<div className="item"> | |
{users.map((user) => { | |
return ( | |
<User | |
key={user.id} | |
firstName={user.first_name} | |
lastName={user.last_name} | |
email={user.email} | |
avatar={user.avatar} | |
/> | |
); | |
})} | |
</div> | |
</main> | |
); | |
} | |
} | |
export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PropTypes from 'prop-types'; | |
function User({ firstName, lastName, email, avatar }) { | |
return ( | |
<div> | |
<h1> | |
{firstName} {lastName} | |
</h1> | |
<h2>{email}</h2> | |
<img src={avatar} alt={lastName} /> | |
</div> | |
); | |
} | |
User.propTypes = { | |
firstName: PropTypes.string.isRequired, | |
lastName: PropTypes.string.isRequired, | |
email: PropTypes.string.isRequired, | |
avatar: PropTypes.string.isRequired, | |
}; | |
export default User; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment