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

React Native Variable Undefined

$
0
0

Im not understanding why my varaible is undefined, i firstly declare my variable geojsonData as a let so i am able to change the values later in the code. In my useEffect where i use an if statement to check if check if the visibility is true, i set my geojsonData's value. However, in the return of the function my values are not set.

Is there a way i can set the geojson data?

let geojsonData;...useEffect(() => {if(componentVisible == true){   geojsonData = {     type: Type,    features: [      {        type: featuresType,        properties: {},        geometry: {          type: geometryType,          coordinates: coordinate,        },      },    ],  };});...return (<View><Geojson geojson={geojsonData}/></View>

After a suggestion in the answer section, i have changed my code to use useState hook. However i am still getting an error for type: Type where it "is not assignable to parameter of type '(prevState: undefined) => undefined'."Updated Code:

const[geojsonData, setGeoData] = useState()...useEffect(() => {if(componentVisible == true){   setGeoData({     type: Type,    features: [      {        type: featuresType,        properties: {},        geometry: {          type: geometryType,          coordinates: coordinate,        },      },    ],  });});...return (<View><Geojson geojson={geojsonData}/></View>

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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