Skip to content

Instantly share code, notes, and snippets.

@nikolaymatrosov
Created June 9, 2016 16:55
Show Gist options
  • Save nikolaymatrosov/536ccbcb4c8bc83ee314771f70de5d87 to your computer and use it in GitHub Desktop.
Save nikolaymatrosov/536ccbcb4c8bc83ee314771f70de5d87 to your computer and use it in GitHub Desktop.
Arrow function example
export class Counter extends React.Component<any, any> {
constructor(props) {
super(props);
this.state = {count: props.initialCount};
}
tick = () => {
this.setState({count: this.state.count + 1});
}
render() {
return (
<div onClick={this.tick}>
Clicks: {this.state.count}
</div>
);
}
}
Counter.propTypes = { initialCount: React.PropTypes.number };
Counter.defaultProps = { initialCount: 0 };
@nikolaymatrosov
Copy link
Author

Original code from react docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment