Skip to content

Instantly share code, notes, and snippets.

@femicodes
Created January 12, 2020 16:52
Show Gist options
  • Select an option

  • Save femicodes/22f21b91153d8b3e188af239aa64c0c4 to your computer and use it in GitHub Desktop.

Select an option

Save femicodes/22f21b91153d8b3e188af239aa64c0c4 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
class App extends Component {
state = {
wars: [],
}
componentDidMount() {
fetch('https://swapi.co/api/people')
.then(response => response.json())
.then(res => this.setState({ wars: res.results }));
}
render() {
const id = () => Math.random(10)
return (
<div>
{console.log(this.state.wars)}
{this.state.wars.map(item => (
<div key={id()}>
<ul>
<li>Name: {item.name}</li>
<li>Height: {item.height}</li>
</ul>
</div>
))}
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment