Created
October 9, 2018 02:46
-
-
Save rcdexta/35ec7d991d4bbd535a9e7742ad0229b3 to your computer and use it in GitHub Desktop.
TodoForm.js
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
class TodoForm extends React.Component { | |
static propTypes = { | |
onAddItem: PropTypes.func | |
} | |
state = {value: ''} | |
handleChange = (event) => { | |
this.setState({value: event.target.value}); | |
} | |
addItem = () => { | |
const {value} = this.state | |
if (value && value !== '') { | |
this.props.onAddItem({newItemValue: value}); | |
this.setState({value: ''}) | |
} | |
} | |
render() { | |
return ( | |
<div className="pure-form pure-form-aligned"> | |
<input type="text" value={this.state.value} data-testid="newItemField" | |
className="form-control" placeholder="add a new item..." onChange={this.handleChange}/> | |
<button className="pure-button pure-button-primary" data-testid="addBtn" onClick={this.addItem}>Add</button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment