O'Reilly logo

React Native By Example by Richard Kho

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ListView with section headers

To set up our ListView to accommodate section headers, we need to make some modifications to the way we've been creating ListViews.

First, when we instantiate a new ListView DataSource, we'll be passing it a second callback, sectionHeaderHasChanged. Like rowHasChanged, this one checks to see whether a section header has changed. In your code, it looks something like this:

 this.state = {    ds: new ListView.DataSource({    rowHasChanged: (r1, r2) => r1 !== r2,    sectionHeaderHasChanged: (s1, s2) => s1 !== s2     }),   } 

Then, instead of calling cloneWithRows, we call the similarly named cloneWithRowsAndSections function:

const dataSource = this.state.ds.cloneWithRowsAndSections(this.state.listOfExpenses); 

Finally, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required