Created
July 10, 2016 23:28
-
-
Save biglovisa/f796742a6dc5a3fa1a5f7574ae804a11 to your computer and use it in GitHub Desktop.
SimpleAddNewForm-solution
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
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