Last active
August 25, 2018 19:14
-
-
Save dance2die/5098bb920c1cd569d1c38bf750cd3f94 to your computer and use it in GitHub Desktop.
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
class App extends Component { | |
state = { clickCounts: {} }; | |
onClick = e => { | |
e.persist(); | |
const clickCounts = { ...this.state.clickCounts }; | |
let clickCount = +clickCounts[e.target.name] || 0; | |
clickCounts[e.target.name] = ++clickCount; | |
this.setState({ clickCounts }; | |
console.log( | |
`Button Name (◀️ outside) = ${e.target.name}`, | |
this.state.clickCounts | |
); | |
}; | |
render() { | |
const buttons = [1, 2, 3].map(id => ( | |
<button | |
key={id} | |
name={`button${id}`} | |
onClick={this.onClick} | |
>{`Button #${id}`}</button> | |
)); | |
return <div className="App">{buttons}</div>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment