Genesy91
Genesy91

Reputation: 73

In a SectionList how do i hide the section header of an empty section (data:[])

I'm using react-native's SectionList and can't hide the sectionheaders of the empty sections of my dataset. I want to show only the section headers and the rows of the sections that are not empty.

Upvotes: 6

Views: 5171

Answers (2)

Soyal7
Soyal7

Reputation: 451

<SectionList>
    renderSectionHeader={({ section: { title, data } }) =>
            data.length > 0 && <Text>{title}</Text>
            }
    ...
</SectionList>

Upvotes: 0

Andre Simon
Andre Simon

Reputation: 692

This is what I did:

<SectionList
   renderSectionHeader={({ section }) => (
      section.data.length > 0 ? this._renderHeader(section.title) : (null)
   )}
   ...
/>

Upvotes: 20

Related Questions