Last active
May 1, 2019 21:50
-
-
Save gpDA/3859fb22a4ed2b59e72386a550ba761e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ./components.App.js | |
// decrement function | |
handleIncrement = counter => { | |
// copy the `counters` | |
const counters = [...this.state.counters]; | |
// indexOf corresponding eventActions | |
const index = counters.indexOf(counter); | |
// update the `counters` Object using new `counter` | |
counters[index] = {...counter}; | |
counters[index].value++; | |
// setState at last | |
this.setState({ counters }); | |
} | |
// increment function | |
handleDecrement = counter => { | |
// copy the `counters` | |
const counters = [...this.state.counters]; | |
// indexOf corresponding eventActions | |
const index = counters.indexOf(counter); | |
// update the `counters` Object using new `counter` | |
counters[index] = {...counter}; | |
counters[index].value--; | |
// setState at last | |
this.setState({ counters }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment