how to write a for loop for a componant with api data in react js code example
Example 1: loop through api response in react
renderData() {
if (!this.state.trails) {
return null;
}
return this.state.trails.map(trail => <p>{trail.name}</p>);
}
Example 2: loop through api response in react
render() {
return (
<div>{this.renderData()}</div>
)
}