There are so many questions available and I have tried almost about 12 different ways but none are working. The most efficient one is:
async function removeItemValue(key) {
try {
await AsyncStorage.removeItem(key);
return true;
}
catch (exception) {
return false;
}
}
Then I'm calling it as:
useEffect(() => {
removeItemValue('@cartInfo');
}, []);
I've tried putting it outside of useEffect
hook but still no effect. What am I doing wrong?
UPDATE:
Tried this as well but didn't work:
useEffect(() => {
removeItemValue('@cartInfo').then(() => { console.log('removed') })
}, []);
Also tried
useEffect(() => {
AsyncStorage.removeItem('@cartInfo', () => {
AsyncStorage.getItem('@cartInfo').then((res) => {
console.log("RES IS: " + res);
})
})
}, []);
Still no luck. I'm using v1.12.1 of @react-native-community/async-storage
As we discussed in chat, AsyncStorage.removeItem
was actually working, and the issue is that setItem
was being called too often, so that the value was replaced before being read later in getItem
.