So I have a rough notetaking app in React Native, and the function that’s supposed to delete the currently selected note isn’t working. It’s supposed to work from two ends: longpressing the preview of the note, and from the note viewing screen itself.
I have a couple console.logs in there to track what happens to the notes array during the process, and the selected note is not being filtered. Even so, it’s passing the successful toast. It’s also supposed to navigate back to the home page after a successful execution.
export const deleteNote = async (id, setNotes, navigation) => {
try {
let existingNotes = await loadNotes();
console.log('Existing notes before deletion:', existingNotes);
const newNotes = existingNotes.filter(note => note.id !== id);
console.log('Notes after deletion:', newNotes);
await AsyncStorage.setItem(NOTES_KEY, JSON.stringify(newNotes));
setNotes(newNotes);
successToast('Note deleted successfully!');
navigation.navigate('Home');
} catch (error) {
failToast(`Failed to delete note: ${error}`);
console.log(error);
}
};
C J is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.