Hey guys, am trying to retrieve data from a google spreadsheet using REST API but my data can’t be rendered, can someone help me fix my code here. Thanks
import React, { Component } from 'react';
import './App.css';
class App extends Component {
constructor(){
super();
this.state = {items: {}};
}
componentDidMount() {
fetch(`https://spreadsheets.google.com/feeds/list/1mQWX4cTCKO705NxADRu1Zz2sBABO0f7O52KXWQPTFFA/od6/public/values?alt=json`)
.then(res=>res.json()) //get the result as JSON
.then(items=>{
const data = Object.assign({}, this.state, {items: items});
console.log(data);
this.setState(data);
console.log(this.state);
})
}
render() {
return (
<div>
{
this.state.items && this.state.items.entry ? this.state.items.entry.map(item=><div key={item.gsx$employid}>{item.gsx$name}</div>)
: <div>Loading...</div>
}
</div>
);
}
}
export default App;