Skip to content

Instantly share code, notes, and snippets.

@gil00pita
Forked from gisderdube/class_properties.jsx
Last active February 8, 2019 23:17
Show Gist options
  • Save gil00pita/ae985cbf3c70097f51840e99c918d777 to your computer and use it in GitHub Desktop.
Save gil00pita/ae985cbf3c70097f51840e99c918d777 to your computer and use it in GitHub Desktop.
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a ### Class properties & binding Binding functions in JavaScript is a common task. With the introduction of arrow functions in the ES6 spec, we now have
class Counter extends React.Component {
constructor(props) {
super(props)
this.state = { count: 0 }
}
render() {
return(
<div>
<h1>{this.state.count}</h1>
<button onClick={this._increaseCount}>Increase Count</button>
</div>
)
}
_increaseCount = () => {
this.setState({ count: this.state.count + 1 })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment