Answer the question
In order to leave comments, you need to log in
Adding object to existing React Native AsyncStorage?
Hello. There is the following piece of code:
saveData(id, medicineName) {
let note = { id, medicineName }
let noteList = AsyncStorage.getItem('noteList');
AsyncStorage.setItem('noteList', noteList += JSON.stringify(note));
}
Answer the question
In order to leave comments, you need to log in
saveData(id, medicineName) {
let note = { id, medicineName }
let noteList = AsyncStorage.getItem('noteList');
let parsedNoteList = noteList ? JSON.parse(noteList) : [];
parsedNoteList.push(note);
AsyncStorage.setItem('noteList', JSON.stringify(parsedNoteList));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question