Last active
June 15, 2017 16:35
-
-
Save machnicki/85dff49c663d23f8053a614a1957e75f to your computer and use it in GitHub Desktop.
Event handlers in React - 6
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 } from 'myInputs' | |
class MyComponent extends Component { | |
handleKeyPress = (item) => (e) => { | |
e.preventDefault() | |
if (e.nativeEvent.keyCode === 13) { | |
console.log(`This is enter on item, which is called ${item}!`) | |
} | |
} | |
renderItem(item) { | |
return ( | |
<MyInput | |
onKeyPress={ this.handleKeyPress(item) } | |
/> | |
) | |
} | |
render() { | |
const items = ['Item1', 'Item2', 'Item3'] | |
return ( | |
<div> | |
{ items.map(this.renderItem) } | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does MyInput look like in this case?