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

2

6

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.

Paleoasiatic answered 28/11, 2018 at 12:28 Comment(1)
You should mark @Andre Simon's answer as acceptedDipetalous
B
20

This is what I did:

<SectionList
   renderSectionHeader={({ section }) => (
      section.data.length > 0 ? this._renderHeader(section.title) : (null)
   )}
   ...
/>
Boyse answered 15/1, 2019 at 19:4 Comment(0)
E
0
<SectionList>
    renderSectionHeader={({ section: { title, data } }) =>
            data.length > 0 && <Text>{title}</Text>
            }
    ...
</SectionList>
Eld answered 28/2, 2022 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.