The code of my button is:
<Button style={styles.shopButtonStyle} onPress={async () => { await this.setState({'selectedShop': negozio['@id'] }); await AsyncStorage.setItem('@shop', "test"); }}>
<Text>Scegli</Text>
</Button>
And i go to another page with:
<Button style={styles.shopButtonStyle} onPress={async () => { this.props.navigation.navigate('Bookingstep2');
}}>
<Text>Continua</Text>
</Button>
In the new page i have:
componentDidMount(){
async () => { const shop = await AsyncStorage.getItem('@shop'); console.log(shop); }
}
But the console is empty. Can anyone help me?
You should make your componentDidMount async instead and use try catch to check the error like:
async componentDidMount() {
try {
const shop = await AsyncStorage.getItem('@shop');
console.log(shop);
} catch (error) {
console.log(error);
}
}
There may be any error so you can check error in catch block