I am building a section list. Each section has a different data object with varying values. Because of that I need to render a different component for each section but am having a hard time figuring out how to do so.
Here is my DATA array (two are dummies for now)
const DATA = [
{
title: "Groups",
data: [
{
groupName: "Samwise",
},
],
},
{
title: "Noters"
{
userName: "Merri",
},
],
},
{
title: "Contacts",
data: termIsContact.length ? termIsContact : contacts,
}]
SectionList component
<SectionList
sections={DATA}
keyExtractor={(item, index) => item + index}
renderItem={renderItem}
renderSectionHeader={({ section: { title } }) => (
<View style={tw.style(`justify-center bg-red-100 pl-4`, { height: 28 })}>
<Text style={tw`text-base font-bold`}>{title}</Text>
</View>
)}
/>
How I am rendering the Contacts list
const Item = ({ givenName, familyName }) => (
<TouchableOpacity
onPress={() => toggleContact(`${givenName} ${familyName}`)}
style={tw.style("justify-start pl-4 w-full flex flex-row items-center", {
height: 56,
borderBottomColor: "#aaaaaa",
borderBottomWidth: 1,
})}
>
<Avatar
name={`${givenName} ${familyName}`}
size={32}
backgroundColor={"#D9F3FC"}
labelColor={"#16ade0"}
/>
<Text style={tw.style("text-black text-base pl-2", {})}>
{givenName} {familyName}
</Text>
</TouchableOpacity>
)
const renderItem = ({ item }) => <Item familyName={item.familyName} givenName={item.givenName} />
My thinking is to create an <Item /> to be rendered for each of the sections but just cant figure out how to get each section to render its own style from the data in that sections data object.
Thank you very much in advance