Created
March 9, 2019 05:34
-
-
Save asleepysamurai/c082da463c1f58c0bc6036cd887a0fe9 to your computer and use it in GitHub Desktop.
TodoInput Class Component
This file contains 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
/** | |
* 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