Created
February 2, 2017 14:06
-
-
Save badnorseman/0947a1af5d93802ee0d2feced7b3c319 to your computer and use it in GitHub Desktop.
React Input
This file contains hidden or 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
"use strict"; | |
import React, { Component, PropTypes } from "react"; | |
import { render } from "react-dom"; | |
class Inputfield extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { value: this.props.value }; | |
this.handleChange = this.handleChange.bind(this); | |
} | |
handleChange(ev) { | |
ev.preventDefault(); | |
this.setState({ value: ev.target.value }); | |
} | |
render() { | |
const { id, label, type } = this.props; | |
let value = this.state.value; | |
return ( | |
<div> | |
<input | |
id={id} | |
type={type} | |
value={value} | |
onChange={this.handleChange} /> | |
<label | |
htmlFor={id}> | |
{label} | |
</label> | |
</div> | |
) | |
} | |
} | |
Inputfield.propTypes = { | |
id: PropTypes.string.isRequired, | |
label: PropTypes.string.isRequired, | |
value: PropTypes.oneOfType([ | |
PropTypes.number, | |
PropTypes.string | |
]) | |
}; | |
export default Inputfield |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment