Answer the question
In order to leave comments, you need to log in
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 })
});
Answer the question
In order to leave comments, you need to log in
Try deleting the resulting key with deletevar nextNews = delete dataNew[idElem ]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question