0
class Rnn extends Component{
 constructor(props){
 super(props);
 this.state={
 x:[]
}
}

componentWillMount(){
 var api={
 getroverss(){
 var url="https://fcctop100.herokuapp.com/api/fccusers/top/recent";
 return fetch(url).then((res) => res.json());
}
},
 api.getrovers().then((res) =>{
 this.setState({ x: res
 })
 });
 }
 render(){
 var xx=this.state.x;
 console.table(xx);
 return (
  <h1>print data</h1>
  );
 }}

I have been using this api get data from it. I have managed to ouput the data on console. How do I get(ouput/print) the data on my webpage? (I want to use fetch method only).

sugandh goyal
  • 325
  • 2
  • 4
  • 14

1 Answers1

0

You can use map to iterate over the items and render them to the DOM

{xx.map((x, idx) => {<div key={idx}> {x.username} </div> })}

So, at your discretion, you can choose how to format other data inside xx. Let me add that you might prefer componentDidMount to componentWillMount. See why here

Community
  • 1
  • 1
Rowland
  • 1,728
  • 1
  • 12
  • 19