//@flow import React from "react"; type Props = { label?: string, placeholder?: string, value?: string, type?: string, autofocus?: boolean, onChange: string => void }; class InputField extends React.Component { static defaultProps = { type: "text", placeholder: "" }; field: ?HTMLInputElement; componentDidMount() { if (this.props.autofocus && this.field) { this.field.focus(); } } handleInput = (event: SyntheticInputEvent) => { this.props.onChange(event.target.value); }; renderLabel = () => { const label = this.props.label; if (label) { return ; } return ""; }; render() { const { type, placeholder, value } = this.props; return (
{this.renderLabel()}
{ this.field = input; }} className="input" type={type} placeholder={placeholder} value={value} onChange={this.handleInput} />
); } } export default InputField;