I'm trying to use AsyncStorage to set a value and it always seems to be setting null. I've used async/await in order to do this but I've also tried to whittle down the troubleshooting to just setting a value and checking the callback and I'm still getting null. Any ideas what I'm doing wrong here?
AsyncStorage.setItem('something', 'VALUE')
.then((val) => {
this.setState({storageValue: val ? val : 'EMPTY'});
})
This always gives me "EMPTY" in my state.
I can't find it in the documentation but according to the sample code code setItem does not seem to return anything (the result is ignored in sample code) so maybe the promise does not resolve to anything either.
You could try setting it and then getting it:
AsyncStorage.setItem('something', 'VALUE')
.then(x => AsyncStorage.getItem('something')
.then((val) => {
this.setState({storageValue: val ? val : 'EMPTY'});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With