Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if React Native ListViewDataSource is empty?

Tags:

react-native

I'm passing a ListViewDataSource down as a prop and want the child element to detect whether it's empty or not.

Debugging in Chrome, I see that the _cachedRowCount property is set to 0 when the list is empty.

Is there a better way to detect whether the list view is empty?

like image 241
yogiben Avatar asked Jan 18 '16 10:01

yogiben


1 Answers

Try getRowCount(), for instance:

let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
let dataSource = ds.cloneWithRows(this.state.rows || [])

console.log(dataSource.getRowCount())
like image 94
Samuli Hakoniemi Avatar answered Sep 24 '22 14:09

Samuli Hakoniemi