Last active
February 13, 2022 14:16
-
-
Save juhahinkula/8509089a424817c69584aec9c0db95da to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>React getting started</title> | |
</head> | |
<body> | |
<!-- Root container for react components --> | |
<div id='root'></div> | |
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> | |
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> | |
<script type="text/babel"> | |
const RestList = () => { | |
const [listItems, setListItems] = React.useState([]); | |
React.useEffect(() => { | |
fetch('https://reqres.in/api/users') | |
.then(response => response.json()) | |
.then(responseData => { | |
setListItems(responseData.data) | |
}) | |
.catch(err => console.error(err)) | |
}, []) | |
const itemRows = listItems.map((person) => | |
<tr key={person.id}> | |
<td>{person.first_name}</td> | |
<td>{person.last_name}</td> | |
<td>{person.email}</td> | |
</tr> | |
) | |
return ( | |
<div> | |
<h2>Persons</h2> | |
<table> | |
<tbody> | |
<tr><th>First name</th><th>Last name</th><th>Email</th></tr> | |
{itemRows} | |
</tbody> | |
</table> | |
</div> | |
); | |
} | |
ReactDOM.render(<RestList />, document.getElementById('root')); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment