S
S
string152017-09-17 11:05:15
JavaScript
string15, 2017-09-17 11:05:15

How to remove a component from a list in REACT?

New to react! I'm studying this textbook at random , at the end I get a list of news, you can add news. I wanted to implement the functionality of removing an element from the list, it seems to work, but not quite what I wanted. Removes this code

window.ee.addListener('News.delete', function( idElem ) {

      var dataNew = self.state.news;

      var nextNews = dataNew.map(item => item.id !== idElem ? item : null);
      var deleteNews = nextNews.filter(item => item);

      self.setState({ news: deleteNews })
    });

How can you make it easier? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alexandrovich, 2017-09-17
@RomReed

Try deleting the resulting key with delete
var nextNews = delete dataNew[idElem ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question