Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to use constants from other screen files without exporting

$
0
0

I'd like to use constants from Data.tsx in `OtherScreen.tsx' without exporting the constants. How can I do this? If React Context is the only way, how can I implement that in this situation?

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;

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>