Reputation: 1610
How would I remove a specific id in this setup. I tried to use filter: setNotesDummyData(notesDummyData.filter((o) => { myCondition }));
inside the onChangeItemName
function but can't return right conditions so only one item will get removed.
const NotesContainer = ({
}) => {
const [notesDummyData, setNotesDummyData] = useState([
{
id: '5',
title: 'Holland',
},
{
id: '7',
title: 'Russia',
},
]);
const onChangeItemName = (itemId) => {
//Remove item with specific itemId
};
Upvotes: 2
Views: 5487
Reputation: 2323
const onChangeItemName = (itemId) => {
setNotesDummyData(notesDummyData.filter(({ id }) => id !== itemId));
};
Upvotes: 3