Last active
April 6, 2016 07:41
-
-
Save machnicki/fc9982714b872618c2ec3d959cdfe160 to your computer and use it in GitHub Desktop.
Event handlers in React - 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { MyInput, MyAnotherInput } from 'myInputs' | |
class MyComponent extends Component { | |
constructor(props) { | |
super(props) | |
this.handleChange = this.handleChange.bind(this) | |
this.handleClick = this.handleClick.bind(this) | |
this.handleKeyPress = this.handleKeyPress.bind(this) | |
} | |
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> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment