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:

  1. 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;

  2. creators of react evangelise immutable objects in order work w/ react, choice fine.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -