Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created August 25, 2018 19:24
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 dance2die/8afe95dedfbe62e77de813ae2b41a2b0 to your computer and use it in GitHub Desktop.
Save dance2die/8afe95dedfbe62e77de813ae2b41a2b0 to your computer and use it in GitHub Desktop.
onClick = e => {
e.persist();
const clickCounts = { ...this.state.clickCounts };
let clickCount = +clickCounts[e.target.name] || 0;
clickCounts[e.target.name] = ++clickCount;
// - From this,
// this.setState({ clickCounts });
// + To this
this.setState({ clickCounts }, () =>
console.log(
`Button Name (▶️️ inside callback) = `,
this.state.clickCounts
)
);
console.log(
`Button Name (◀️ outside callback) = ${e.target.name}`,
this.state.clickCounts
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment