undefined is not an object (evaluating 'allRowsIDs.length') (React-Native)
Your initial problem is that you've set this.state.dataSource
to the string 'init'
. You want that to be pointing to the datasource that you declared earlier.
You can solve your first problem, if you change:
this.state = {
dataSource: 'init',
};
to this:
this.state = {
dataSource: ds
};
However, that's just going to get you to a new error message. Something to the effect of Objects are not valid as a React child...
. You can fix that by changing your render function to return a simple string rather than the whole object. I'll suggest you start with the title and move from there. Try this and you should be on your way:
render() {
return (
<View style={styles.container}>
<ListView
dataSource={this.state.dataSource}
renderRow={(rowData) => <Text>{rowData.title}</Text>}
/>
</View>
);
}
This problem could be caused by trying to render ListView
with a falsy list.
I just opened an app I hadn't used in like 6 months and it exploded fantastically because the database was wiped and this ListView
was trying to render and getting an empty list from Redux mapStateToProps
.
Long debug story short, I put an empty list check in the render method:
render() {
if (!this.props.employees.length) {
return (
<View>
<Text>NO EMPLOYEES TO LIST</Text>
</View>
)
}
return (
<ListView
enableEmptySections
dataSource={this.dataSource}
renderRow={this.renderRow}
/>
)
}
If you somehow keep getting it after that, put a falsy check in renderRow
.