Skip to content

Instantly share code, notes, and snippets.

@badnorseman
Created February 2, 2017 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badnorseman/0947a1af5d93802ee0d2feced7b3c319 to your computer and use it in GitHub Desktop.
Save badnorseman/0947a1af5d93802ee0d2feced7b3c319 to your computer and use it in GitHub Desktop.
React Input
"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