I am trying to take json list that I've received from API and want to render those json list on the browser. I figured out how to fetch data from REST API in the backend, now I want to take those json list and render it on the browser. Here is what I learned and what I tried:
import React from 'react';
export default class peopleList extends React.Component {
state = {
values: []
}
componentDidMount() {
fetch('http://localhost:3005/people')
.then(function(res) {
return res.json();
}).then(function(json) {
this.setState({
values: json
})
});
}
render(){
return <div className="drop-down">
<p>I would like to render json list on the browser </p>
<select>{
this.state.values.map((obj) => {
return <option value={obj.id}>{obj.name}</option>
})
}</select>
</div>;
}
}
Desired output:
I created a simple panel frame where I want to place json list data. for the simplicity I just want to display each line for the time being. How can I make this happen? can anyone point me out how to get this done more efficiently? Thanks
in this attached output, I used example panel frame that I want to put my json list on the panel. I admit that data that different though.
