Created
November 26, 2018 08:41
-
-
Save rcdexta/a0ae72f870cabf2da260bf25673a2833 to your computer and use it in GitHub Desktop.
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 from "react"; | |
export default class NewItem extends React.Component { | |
state = { value: "" }; | |
updateValue = evt => { | |
this.setState({ value: evt.target.value }); | |
}; | |
addNewItem = () => { | |
this.props.onAdd(this.state.value); | |
this.setState({ value: "" }); | |
}; | |
render() { | |
return ( | |
<div className="form"> | |
<input | |
type="text" | |
placeholder="add a new item..." | |
value={this.state.value} | |
onChange={this.updateValue} | |
onBlur={this.addNewItem} | |
/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment