import React, { Component } from 'react';
import './App.css';
class App extends Component{
constructor(){
super();
this.state={
users:null
}}
componentDidMount()
{
fetch('https://reqres.in/api/users').then((resp)=>{
resp.json().then((result)=>{
console.warn(result.data)
this.setState({users:result.data})
});
})
}
render(){
return(
<div>
<h1>Fetch API Data</h1>
{
this.state.users ?
this.state.users.map((item,i) =>
<div>{i} --- {item.first_name} --- {item.last_name} --- {item.email}</div>
)
:
null
}
</div>
)}
}
export default App;
No comments:
Post a Comment