tigran
11/23/2018 - 1:25 PM

bind this

import React, { Component } from 'react';
import Todo from './Todo';

class Todos extends Component {
    constructor(props) {
      super(props);
      this.test = this.test.bind(this);
    }
    
    test() {
      //this
    }
    
    test1() {
      //this
    }

    test2(id) {
      //this
    }
    
    test3 = () => {
      //this
    }

    render() {
        return (
            <div>
              <button onClick={ this.test }>X</button>
              <button onClick={ this.test1.bind(this) }>X</button>
              <button onClick={ () => this.test2() }>X</button>
              <button onClick={ this.test3 }>X</button>
            </div>
        )
    }
}

export default Todos;