2

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

  };
1
  • 1
    You need to return your condition to the filter and in wrapping your condition in {}-brackets, it does not get returned and thus not filtered. Commented Aug 2, 2019 at 10:45

1 Answer 1

3
const onChangeItemName = (itemId) => {
    setNotesDummyData(notesDummyData.filter(({ id }) => id !== itemId));
};
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, this works. How would I go about if I would like to .splice away that item?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.