Reputation: 311
I want to update single item in array, and I don't know how to do it. I tried this approach but it doesn't work.
async _updatePoints (value) {
await AsyncStorage.setItem(`@results:${value.scoreId}`, JSON.stringify(value));
this._updateList();
}
As you see, my key in storage is results, and i tried to find it my scoreId which is generated random id.
scoreId: uuid.v4()
Upvotes: 0
Views: 1353
Reputation: 3184
You're close, but your syntax is just slightly off. You're trying
AsyncStorage.setItem(`@results:${value.scoreId}`, JSON.stringify(value));
which maps out to
AsyncStorage.setItem(`@[key]:[key for value]`, [value for value]);
The correct syntax is actually
AsyncStorage.setItem(`@[store]:[key]`, {[key for value]:[value for value]});
which maps out to
AsyncStorage.setItem(`@appName:results`, JSON.stringify({scoreId:value}));
Upvotes: 1