I have a function onTagSelected() that updates now a single value for a key inside a object:
const NotesContainer = ({
}) => {
const [notesDummyData, setNotesDummyData] = useState([
{
id: '5',
title: 'Sauna',
tag: 'relax',
},
{
id: '7',
title: 'Finland',
tag: 'nordics'
},
]);
const onTagSelected = (selectedTag, itemId) => {
setNotesDummyData(notesDummyData.map((x) => {
if (x.id !== itemId) return x;
return { ...x, tag: selectedTag };
}));
};
Now I would like to change the function and be able to take many tags. How should I go about modify the function to push new tag values to the new nested tag: array.
const [notesDummyData, setNotesDummyData] = useState([
{
id: '5',
title: 'Sauna',
tag: ['relax', 'wellness']
},
{
id: '7',
title: 'Finland',
tag: ['nordics', 'winter']
},
]);
const onTagSelected = (selectedTag, itemId) => {
// Push new tag to nested array for specific item -> tag: ['nordics', 'winter', 'selectedTag']
};