follow along
This commit is contained in:
parent
6691671c86
commit
70992d6cb0
2 changed files with 12 additions and 6 deletions
|
|
@ -42,9 +42,15 @@ const App = ({ startingNotes = [] }) => {
|
|||
const note = notes.find((n) => n.id === id);
|
||||
const changedNote = { ...note, important: !note.important };
|
||||
|
||||
noteService.update(id, changedNote).then((response) => {
|
||||
setNotes(notes.map((note) => (note.id === id ? response.data : note)));
|
||||
});
|
||||
noteService
|
||||
.update(id, changedNote)
|
||||
.then((response) => {
|
||||
setNotes(notes.map((note) => (note.id === id ? response.data : note)));
|
||||
})
|
||||
.catch((error) => {
|
||||
alert(`The note '${note.content}' was already deleted from server.`);
|
||||
setNotes(notes.filter((n) => n.id !== id));
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ const update = (id, newObject) => {
|
|||
};
|
||||
|
||||
export default {
|
||||
getAll: getAll,
|
||||
create: create,
|
||||
update: update,
|
||||
getAll,
|
||||
create,
|
||||
update,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue