reactjs - Should I update lists in place with React? -
to delete item list, created new list not contain deleted item, , replaced old list new. "right" way or should edit list in place? suspect may inefficient js.
destroy: function(chosenitem) { var newitems = this.state.items.filter(function(item) { return chosenitem.id != item.id; }); this.setstate({items:newitems}); }
a couple of things:
if such items have sort of persistence mechanism attached, consider using action architecture [see flux, reflux...], not set state of component directly, delegate deletion separate entity, later on notify component of update;
creators of react evangelise immutable objects in order work w/ react, choice fine.
Comments
Post a Comment