Users
Starting point for creating JSFiddles with React.
by ddrraaggaa
HTML
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
Babel + JSX
class Users extends React.Component {
constructor(props) {
super(props)
this.state = {
users: []
}
}
componentDidMount() {
fetch(this.props['data-url'])
.then((response)=>response.json())
.then((users)=>this.setState({users: users}))
}
render() {
return <div className="container">
<h1>List of Users</h1>
<table className="table-striped table-condensed table table-bordered table-hover">
<tbody>{this.state.users.map((user)=>
<tr key={user.id}>
<td>{user.first_name} {user.last_name}</td>
<td> {user.email}</td>
<td> {user.ip_address}</td>
</tr>)}
</tbody>
</table>
</div>
}
}
let dataUrl = 'https://raw.githubusercontent.com/azat-co/react-quickly/master/ch05/users/real-user-data.json'
ReactDOM.render(
<div>
<Users data-url={dataUrl}/>
</div>,
document.getElementById('container')
)