1class Foo extends Component {
2 constructor(props) {
3 super(props);
4 this.handleClick = this.handleClick.bind(this);
5 }
6 handleClick() {
7 console.log('Click happened');
8 }
9 render() {
10 return <button onClick={this.handleClick}>Click Me</button>;
11 }
12}
1export default class Archive extends React.Component {
2
3 saySomething(something) {
4 console.log(something);
5 }
6
7 handleClick(e) {
8 this.saySomething("element clicked");
9 }
10
11 componentDidMount() {
12 this.saySomething("component did mount");
13 }
14
15 render() {
16 return <button onClick={this.handleClick.bind(this)} value="Click me" />;
17 }
18}