How to pass data to SectionList?
what's wrong is the first you try to pass a function to section props, not a value. to get value return from a function, you need to execute that function. Example :
sections={(()=>[
{data: [{title:123},{title:"aaa"}], key: "aaa"},
{data: [{title:333},{title:"bbbb"}], key: "bbb"},
{data: [{title:123},{title:"aaa"}], key: "ccc"},
]) () <<< execute function
}
/>
Sections props require an array not a function. To use a function in sections props, this function must return an array. The array should contain a string key, and a data object. You can use many parameter in this object, for must information you can consult this page
example:
export default class Example extends React.Component {
selectionList = () => {
return([
{data: [{title:123},{title:"aaa"}], key: "aaa"},
{data: [{title:333},{title:"bbbb"}], key: "bbb"},
{data: [{title:123},{title:"aaa"}], key: "ccc"},
])
}
render () {
return (
<View>
<SectionList
renderItem={({item}) => <View><Text> title={item.title}</Text></View>}
renderSectionHeader={({section}) => <View><Text> title={section.key}</Text></View>}
sections={this.selectionList()}
/>
</View>
)
}
}