Skip to content

Instantly share code, notes, and snippets.

@biglovisa
Created July 10, 2016 23:28
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 biglovisa/f796742a6dc5a3fa1a5f7574ae804a11 to your computer and use it in GitHub Desktop.
Save biglovisa/f796742a6dc5a3fa1a5f7574ae804a11 to your computer and use it in GitHub Desktop.
SimpleAddNewForm-solution
import React, { Component, PropTypes } from 'react';
class SimpleAddNewForm extends Component {
constructor(props) {
super(props);
this.state = { value: '' }
this.handleChange = () => this._handleChange();
this.handleClick = () => this._handleClick();
}
_handleChange(e) {
this.setState({ value: e.target.value });
}
_handleClick() {
this.props.handleSubmit(this.state.value);
}
render() {
this.inputField = <input placeholder={this.props.inputFieldPlaceholder}
value={this.state.value}
onChange={this.handleChange} />
this.button = <button onClick={this.handleClick} disabled={!this.state.value} >{this.props.title}</button>
return (
<div className='add-new-form'>
{this.inputField}
{this.button}
</div>
);
}
}
SimpleAddNewForm.PropTypes = {
title: PropTypes.string.isRequired,
inputFieldPlaceholder: PropTypes.string.isRequired,
handleSubmit: PropTypes.func.isRequired
};
export default SimpleAddNewForm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment