This question is similar to some that have already been asked, such as (Can you make render() method in React Native async?), however none of these solutions I have found so far work for me. I am attempting to display a value from storage, however it needs to be obtained asynchronously, so when I am trying to render it returns an unresolved promise. These functions store and get the data asynchronously:
const storeData = async () => {
try {
const value= "hello"
await AsyncStorage.setItem('@storage_Key', value)
} catch (e) {
}
}
const getData = async (key:string) => {
return (<Text>{await AsyncStorage.getItem('@storage_Key')}</Text>)
}
...and then in my return I am trying to do this:
<Button
onPress={() => storeData()}
title="Store"
color="#841584"/>
{getData()}
Which I want to display a button that saves data (working I think), and then display that data in a text field. However I keep receiving unresolved promise errors. How can I render something alternate until the value is loaded, and display the data without an unresolved promise?