I have a RN/Expo project that, at times, returns a null value because the data just hasn't had the time to load.
The data is coming from an AWS server.
If I refresh the page, this will normally fix itself, however this is not a long term solution.
How can I modify this function so that it will run again, if, and only if, it returns a "null" response for any of the variables?
Below is my code:
const [ firstName, getFirstName ] = useState('')
const [ phone, getPhone ] = useState('')
const [ email, getEmail ] = useState('')
const [ userPhoto, getUserPhoto ] = useState(null)
useEffect(()=>{
const info_response = server_grab.get_user_info().then(response=>{
const displayName = async()=>{
getFirstName(
<Text style = {styles.title}>
{response.first_name} {response.last_name}
</Text>
)
getPhone(
<Text style = {styles.box_text}>
{response.phone}
</Text>
)
getEmail(
<Text style = {styles.box_text}>
{response.email}
</Text>
)
}
)
}
const displayPhoto = async () =>{
const photo_response = server_grab.download_profile_photo().then(response=>{
getUserPhoto(response.photo_data.raw_data)
}
)
}
displayPhoto()
displayName()
...
return(
<View>
{userPhoto && <Avatar.Image source= {{uri:`data:image/jpg;base64,${userPhoto}`}}/>}
</View>
<View>
<Text>{firstName}</Text>
<Text>{email}</Text>
<Text>{phone}</Text>
</View>
)