I want to pass in the countryCases
and countryDeaths
constants that use useState
from the Data.tsx
file. I want to pass them in and use them in the OtherScreen.tsx
file. How can I do this?
Data.tsx
interface DataCardProps { onPress: () => void;}const Covid19DataCard = ({ onPress }: DataCardProps) => { const [earliest2, setEarliest2] = useState([]); const [countryDeaths, setcountryDeaths] = useState(Number); const [countryCases, setcountryCases] = useState(Number); useEffect(() => { axios .get("https://coronavirus-19-api.herokuapp.com/countries") .then((response) => { setEarliest2(response.data); const enteredCountryName = countryNameshort; const countryArray = response.data.filter( (item) => item.country === enteredCountryName ); const resCountryDeaths = countryArray[0].deaths; setcountryDeaths(resCountryDeaths); const resCountryCases = countryArray[0].cases; setcountryCases(resCountryCases); }) .catch((err) => { console.log(err); }); }, []);}
OtherScreen.tsx
import Data from './Data';const OtherScreen = ({ navigation,}: StackNavigationProps<Routes, "SearchScreen">) => {<Text>{Data.countryCases}</Text> //???}export default OtherScreen;
They both use different props, and if I try to pass in Data.countryCases
, I get an error Property 'countryCases' does not exist on type '({ onPress }: DataCardProps) => Element'.
Any help is appreciated :)