An Interactive Demonstration: Explore Expo Snack
https://i.sstatic.net/33AVW.png
To resolve this issue, start by passing the index
parameter to ComponentOne
from the file App.js
.
const App = () => {
return (
<SafeAreaView style={styles.container}>
<FlatList
data={DATA}
renderItem={({item, index}) => <ComponentOne name={item.title} index={index}/>}
keyExtractor={(item) => item.id}
/>
</SafeAreaView>
);
};
Utilize this passed prop value to dynamically render ComponentTwo
within ComponentOne
, as illustrated below:
//...const
ComponentOne = (props: ComponentOneProps) => {
return (
<View style={{ margin: 15, backgroundColor: 'yellow' }}>
<FlatList
data={recent}
renderItem={({ item }) => {
console.log("hello")
// @ts-ignore
return props.index == 0?<ComponentTwo name={item.name} />:null;
}}
keyExtractor={(item) => item.idd}
/>
//...