Skip to content

Instantly share code, notes, and snippets.

@rcdexta
Created November 26, 2018 08:41
Show Gist options
  • Save rcdexta/a0ae72f870cabf2da260bf25673a2833 to your computer and use it in GitHub Desktop.
Save rcdexta/a0ae72f870cabf2da260bf25673a2833 to your computer and use it in GitHub Desktop.
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