From 47cde492e22806e05f5a2d362be6b846ed036434 Mon Sep 17 00:00:00 2001 From: usong Date: Tue, 20 Sep 2016 00:15:54 +0800 Subject: [PATCH] fix a bug - line 72 ,change to Immutability Helper to update the states. --- app/KanbanBoardContainer.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/KanbanBoardContainer.js b/app/KanbanBoardContainer.js index df9fe22..3f2be0a 100644 --- a/app/KanbanBoardContainer.js +++ b/app/KanbanBoardContainer.js @@ -69,8 +69,25 @@ class KanbanBoardContainer extends Component { .then((responseData) => { // When the server returns the definitive ID // used for the new Task on the server, update it on React - newTask.id=responseData.id - this.setState({cards:nextState}); + //newTask.id=responseData.id + // using "Immutability Helper update" to update the state of cards + let taskIndex = this.state.cards[cardIndex].tasks.findIndex((element,index,array) => { + if (element.id == newTask.id ) { + return element; + } + }); + let newCars = update(this.state.cards, { + [cardIndex]: { + tasks: { + [taskIndex] : { + id : { + $apply:() => responseData.id + } + } + } + } + }); + this.setState({cards:newCars}); }) .catch((error) => { this.setState(prevState);