Skip to content

Instantly share code, notes, and snippets.

@Manntrix
Created July 9, 2019 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manntrix/7d319a27267ebdfaa2b39e93fd0a6299 to your computer and use it in GitHub Desktop.
Save Manntrix/7d319a27267ebdfaa2b39e93fd0a6299 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react'
import axios from '../../axios'
export default class users extends Component {
constructor(props) {
super(props);
this.state = {
Users: []
};
}
getUsersData() {
axios
.get(`/users`, {})
.then(res => {
const data = res.data
console.log(data)
const users = data.map(u =>
<div>
<p>{u.id}</p>
<p>{u.name}</p>
<p>{u.email}</p>
<p>{u.website}</p>
<p>{u.company.name}</p>
</div>
)
this.setState({
users
})
})
.catch((error) => {
console.log(error)
})
}
componentDidMount(){
this.getUsersData()
}
render() {
return (
<div>
{this.state.users}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment