As I work on my React Native application, I encountered a challenge when trying to display Facebook page status using the Facebook API in a ListView. Thankfully, this tutorial provided me with valuable insight and allowed me to successfully display the latest status in my app.
However, my attempts to show all the statuses in the ListView led to an error message: "undefined is not an object(evaluating 'Object.keys(dataBlob[sectionID])')". After reading a Stack Overflow post, I learned that this error occurs because I was running the cloneWithRows() function on an object rather than an Array. Despite trying to rectify this issue, I am still unable to overcome the error.
If anyone could offer assistance, it would be greatly appreciated. Here is a snippet of the JSON structure generated by the Facebook API:
{"data":[{"message":"Test","created_time":"2016-05-31T13:36:56+0000","id":"1602039116775292_1605827029729834"},
{"message":"Hello","created_time":"2016-05-31T13:36:50+0000","id":"1602039116775292_1605827006396503"},
Below are excerpts from my index.ios.js file:
constructor(props){
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
loaded: false,
};
}
componentDidMount(){
this.fetchData();
}
fetchData(){
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData.timeline), //The problem is here
loaded: true,
});
})
.done();
}
render(){
if (!this.state.timelines) {
return this.renderLoadingView();
}
return(
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderStatus}
style={styles.listView}
/>
);
In particular, the line causing issues is:
dataSource: this.state.dataSource.cloneWithRows(responseData.timeline),
I attempted to replace 'timeline' with 'data', but this resulted in the data not loading and constantly displaying the LoadingView screen.
Please let me know if you require additional code or information. Your help is truly appreciated.
Thank you for your support.