Skip to content

Instantly share code, notes, and snippets.

@asleepysamurai
Created March 9, 2019 05:34
Show Gist options
  • Save asleepysamurai/c082da463c1f58c0bc6036cd887a0fe9 to your computer and use it in GitHub Desktop.
Save asleepysamurai/c082da463c1f58c0bc6036cd887a0fe9 to your computer and use it in GitHub Desktop.
TodoInput Class Component
/**
* TodoInput Component
*/
import React, { Component } from 'react';
class TodoInput extends Component {
constructor(props) {
super(props);
this.state = {
text: ''
};
}
onTextChange = (ev) => {
this.setState({ text: ev.currentTarget.value });
}
addTodoItem = () => {
this.props.onAdd(this.state.text);
this.setState({ text: '' });
}
render() {
return (
<div
className="todo-input">
<input
type="text"
onChange={this.onTextChange}
value={this.state.text}
placeholder="Enter Todo Here" />
<button
onClick={this.addTodoItem}>
Add Todo
</button>
</div>
);
}
};
export default TodoInput;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment