for loop return and get call react js code example
Example 1: loop through api response in react
render() {
return (
<div>{this.renderData()}</div>
)
}
Example 2: loop through api response in react
renderData() {
if (!this.state.trails) {
return null;
}
return this.state.trails.map(trail => <p>{trail.name}</p>);
}