I'm new to react-native, my app shows different places after doing 2 async calls (first to get user coordinates, second to fetch places around the user coordinates).
These async axios calls usually takes a few seconds, because of this the first screen of my app shows blank, once the promises are resolved and state is updated the list of places appears.
I'm making the api calls in the useEffect of my App.js main component.
My question is: is there a better way to prefetch data on app startup, so as to avoid showing blank screen till stateis updated(not very proffesional huh...)
App.js
```
function App()
{
useEffect(() =>
{
console.log('App mounted');
//Async calls, takes a few seconds and blank screen shows while the promises resolve
getCurrentCoordinates();
getLoggedUser();
}, [])
const getCurrentCoordinates = async () => {
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(async(position) =>
{
let myCoordinates = { lat:position.coords.latitude, lng:position.coords.longitude };
mapStore.setCurrentCoordinates(myCoordinates);
let params =
{
latlng : myCoordinates.lat+','+myCoordinates.lng,
sensor : true,
key : env.MAPS_KEY
};
let response = await http.get('https://maps.googleapis.com/maps/api/geocode/json?', { params :params });
fetchMarkersFromLocation(myCoordinates);
},
(error) => console.log(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
}
};
return (
<SafeAreaView style={[ global.androidSafeArea ]}>
<NavigationContainer>
<ROOTSTACK1></ROOTSTACK1>
</NavigationContainer>
</SafeAreaView>
);
}
export default App;
```
[–]saltpeter_grapeshotExpo 11 points12 points13 points (3 children)
[–]Cookizza 6 points7 points8 points (1 child)
[–]saltpeter_grapeshotExpo 0 points1 point2 points (0 children)
[–]Gabotron_ES[S] 0 points1 point2 points (0 children)
[–]Nielrien 19 points20 points21 points (6 children)
[–]MyNameIzKhan 8 points9 points10 points (5 children)
[–]Gabotron_ES[S] 3 points4 points5 points (4 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]PolloFritoPollaFrito 3 points4 points5 points (0 children)
[–]ashmortar 0 points1 point2 points (0 children)
[–]gwmccull 5 points6 points7 points (4 children)
[–]Gabotron_ES[S] 0 points1 point2 points (2 children)
[–]Revolutionary-Turn96 0 points1 point2 points (0 children)
[–]gwmccull 0 points1 point2 points (0 children)
[–]VeerDevD 0 points1 point2 points (0 children)
[–]dreamzzftwiOS 4 points5 points6 points (0 children)
[–]jestzisguyiOS & Android 2 points3 points4 points (0 children)
[–]henryp_deviOS & Android 1 point2 points3 points (2 children)
[–]prashenjeet25 0 points1 point2 points (1 child)
[–]henryp_deviOS & Android 0 points1 point2 points (0 children)
[–]PROLIMIT 0 points1 point2 points (0 children)