I have a function onTagSelected() that updates now a single value for a key inside a object:
const NotesContainer = ({
}) => {
const [notesDummyData, setNo
You can use es6 destructuring to add new items to an array.
const onTagSelected = (selectedTag, itemId) => {
setNotesDummyData(notesDummyData.map((x) => {
if (x.id !== itemId) return x;
return { ...x, tag: [...x.tag, selectedTag] };
}));
}
spread the previous tag and add selectedTag to end
just change this
return { ...x, tag: selectedTag };
to
return { ...x, tag: [...x.tag, selectedTag] };
Or
return { ...x, tag: x.tag.concat(selectedTag) };