Last active
October 10, 2018 13:03
-
-
Save moskalukigor/9974d1f44065832b0601b5ddba296835 to your computer and use it in GitHub Desktop.
Update object (Nested) with react-addons-update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import update from 'react-addons-update'; | |
let nextState = update(this.state.cards, { | |
[index] : { | |
tasks: {$splice: [[taskIndex, 1]]} | |
} | |
}); | |
//----------------------------------------------------- | |
let nextState = update(this.state.cards, { | |
[cardIndex] : { | |
tasks: { | |
[taskIndex]: { | |
done: { //(Done value = true or false) | |
$apply: (done) => { | |
newDoneValue = !done; | |
return newDoneValue; | |
} | |
} | |
} | |
} | |
} | |
}); | |
//----------------------------------------------------- | |
let newTask = {id: Date.now(), name: taskName, done: false }; | |
let nextState = update(this.state.cards, { | |
[cardIndex] : { | |
tasks: {$push: [newTask]} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment