Skip to content

Instantly share code, notes, and snippets.

@moskalukigor
Last active October 10, 2018 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moskalukigor/9974d1f44065832b0601b5ddba296835 to your computer and use it in GitHub Desktop.
Save moskalukigor/9974d1f44065832b0601b5ddba296835 to your computer and use it in GitHub Desktop.
Update object (Nested) with react-addons-update
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