Horrible Howtos: Binding React Events in es6

Disclaimer: I'm not actually good at react, I'm just learning it. Take nothing here seriously.

Here is our base level component:

import React, { Component } from 'react';

export default class testComponent extends Component{
  //notice that we can use abbreviated functions within the class
  handleClick(){
    console.log('I just done clicked it')
 }
render(){
 return(
	  <h1 onClick={this.handleClick.bind(this)}>Click Me</h1>
 );
}
}

Notice the .bind(this). You want to use this in order to relate to the app properly.

Show Comments

Get the latest posts delivered right to your inbox.