class App extends React.Component {
constructor() {
super();
this.state = {items: []}
}
componentWillMount() {
fetch('https://swapi.co/api/people/?format=json')
.then(response => response.json())
.then(({results: items}) => this.setState({items}))
}
render() {
let items = this.state.items
return (
<div>
<ul>
{items.map((item) =>
<li key={item.id}>
{item.name}
</li>
)}
</ul>
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('container')
);
Here the Array.map render all the properties from object.
I want only 2 objects using array.map method and render only 2 objects, not all
how can I do this ?
Regards,