Reputation: 47
I'm developing an app in Expo and am facing a very simple problem.
Inside of my App.js:
AsyncStorage.setItem("test", "testVal").then((res) => {
AsyncStorage.getItem("test", (value) => {
console.log("VALUE: " + value);
});
});
The code above logs VALUE: null
, instead of VALUE: test
. Any ideas on what could be going wrong?
(Using EXPO Version 3.17.21)
Upvotes: 0
Views: 376
Reputation: 3253
This is getItem
signature:
static getItem(key: string, [callback]: ?(error: ?Error, result: ?string) => void): Promise
So the first argument of the callback is error
. try:
AsyncStorage.setItem("test", "testVal").then((res) => {
AsyncStorage.getItem("test", (err, value) => {
console.log("VALUE: " + value);
});
})
Upvotes: 1