Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of React Native ListView's 'rowHasChanged'?

Tags:

react-native

According to React Native's ListView documentation, a ListView datasource should be declared with the following standard implementation of rowHasChanged in order determine when the given row has changed:

var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});

My question here is: what's the idea behind having to provide such an obvious and trivial implementation of detecting whether or not a row has changed? Are there any cases where this implementation doesn't hold true? I would've imagined that ListViewDataSource would've at least provided a default implementation for such a trivial function instead of having to copy and paste this code every single time we create a datasource.

like image 512
Tarek Avatar asked Nov 08 '22 11:11

Tarek


1 Answers

I can't speak for why there was no default provided but the reason it is available is if you have a list view with complex objects and know a more efficient way to know if a row has changed... for example if all of your list items had an ID property and you knew that if the ID was the same then the entire object was the same you could do:

var ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1.id !== r2.id }); 
like image 166
rmevans9 Avatar answered Nov 15 '22 14:11

rmevans9