adrianvlupu
10/20/2016 - 4:01 PM

Event handlers in React - 2

Event handlers in React - 2

import React, { Component } from 'react'
import { MyInput, MyAnotherInput } from 'myInputs'

class MyComponent extends Component {
  handleChange = (e) => e.preventDefault()
  
  handleClick = (e) => e.preventDefault()
  
  handleKeyPress = (e) => {
    e.preventDefault()
    
    if (e.nativeEvent.keyCode === 13) {
      console.log('This is enter!')
    }
  }
  
  render() {
    return (
      <div>
        <MyInput
          onChange={ this.handleChange }
          onClick={ this.handleClick }
          onKeyPress={ this.handleKeyPress }
        />
        <MyAnotherInput
          onChange={ this.handleChange }
          onClick={ this.handleClick }
          onKeyPress={ this.handleKeyPress }
        />
      </div>  
    )
  }
}