For testing how a flatlist works, I'm trying to display items in it using another component for the "renderItem" function.
Here's my code that renders the FlatList:
export default function HomeBody() {
const data = [];
let movie1: MediaDetails = {
title: 'Movie1',
image: '../../assets/TestImage.png'
};
let movie2: MediaDetails = {
title: 'Movie1',
image: '../../assets/TestImage.png'
};
let movie3: MediaDetails = {
title: 'Movie1',
image: '../../assets/TestImage.png'
};
let myQueue: SwimlaneItem = {
title: 'My queue',
media: [
movie1,
movie2,
movie3,
]
}
let movie4: MediaDetails = {
title: 'Movie4',
image: '../../assets/TestImage.png'
};
let movie5: MediaDetails = {
title: 'Movie5',
image: '../../assets/TestImage.png'
};
let movie6: MediaDetails = {
title: 'Movie6',
image: '../../assets/TestImage.png'
};
let upcomingQueue: SwimlaneItem = {
title: 'My queue',
media: [
movie4,
movie5,
movie6,
]
}
data.push(myQueue);
data.push(upcomingQueue);
return(
<View style={styles.container}>
<FlatList
style={styles.flatlist}
data={data}
renderItem={({ item }: any) =>
<Swimlane swimlaneItem={item} />
}
/>
</View>
)
}
And here's my component "per item" or "Swimlane":
export default function Swimlane({ swimlaneItem }: any) {
return (
<View>
<Text>{swimlaneItem}</Text>
{/* <FlatList
horizontal
data={swimLaneItem.media}
renderItem={({ media }: any) =>
<>
<Text>{media.title}</Text>
<Image source={media.image} />
</>
}
/> */}
</View>
)
}
So what I want is for the flatlist to display 2 "lanes" or items, these are "myQueue" and "upcomingQueue". Each "lane" will have a title and a media array, containing items which have a "title" and an "image". So in my "Swimlane" component I want to do "swimlaneItem.title" for the text and have another flatlist to render all the "media" objects, which will in turn have a "title" and "media" property.
How can I achieve this? Right now the following error is thrown:
"Objects are not valid as a React child (found: object with keys {title, media}). If you meant to render a collection of children, use an array instead"
the reason for the error is that your passing the entire render item object into a component instead of a string which is what Text expects