Im a begginer in React Native. Im trying to pass data between two components in my app. I have components - Home.js and MyModal.js.
In the first component - Home.js - I have an array with some data and FlatList component. Home.js displays data in my app correctly. Additionally, in home.js, I'm trying to display Modal, when user clicks on a Card in TouchableOpacity component:
<TouchableOpacity onPress={() => <MyModal />}>
<Card></Card> </TouchableOpacity>
In the second component - MyModal.js- I'm trying to display data /item.title/ and /item.body/ from home.js.
Here is all code:
home.js:
import React, { useState } from "react";
import {StyleSheet,View,Text,FlatList,TouchableOpacity} from "react-native";
import Card from "../components/card";
import MyModal from "../components/myModal"
function Home({ navigation }) {
const [reviews, setReviews] = useState([
{
body: "lorem ipsum",
key: " 1",
title: "Flower",
},
{
key: "2",
title: "Two flowers",
body: "lorem ipsum",
}
]);
return (
<View style={styles.container}>
<FlatList
data={reviews}
renderItem={({ item }) => (
<TouchableOpacity onPress={() => <MyModal />}>
<Card>
<Text>{item.title}</Text>
<Text>{item.body}</Text>
</Card>
</TouchableOpacity>
)}
/>
</View>
);
}
myModal.js
import React from "react";
import { View, Text, Button, StyleSheet } from "react-native";
import Card from "../components/card";
export default function MyModal({ route, navigation }) {
return (
<View>
<Card>
<Text>{data.title}</Text>
<Text>{data.body}</Text>
</Card>
</View>
);
}
Here is exaple what I want to display:
Screen after click (opened MyModal.js with data from home.js):

Here is the codesandbox: https://codesandbox.io/s/youthful-fermat-lui4g
I will be grateful for any advice
