MCPcopy Create free account
hub / github.com/kenberkeley/react-demo / TodoInput

Class TodoInput

src/components/Todo/TodoInput.js:4–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2import handleChange from 'MIXIN/handleChange'
3
4export default class TodoInput extends Component {
5 constructor (props) {
6 super(props)
7 this.state = { inputVal: '' }
8 this.handleChange = handleChange.bind(this)
9 }
10
11 handleSubmit () {
12 let content = this.state.inputVal.trim()
13 if (!content) return
14
15 this.props.addTodo(content)
16 this.setState({ inputVal: '' }) // 清空输入框
17 }
18
19 render () {
20 return (
21 <form onSubmit={
22 (e) => {
23 e.preventDefault() // 防页面跳转
24 this.handleSubmit()
25 }
26 }>
27 <div className="form-group">
28 <input
29 type="text"
30 className="form-control"
31 name="inputVal"
32 placeholder="请输入待办事项,敲回车确认添加"
33 required
34 value={this.state.inputVal}
35 onChange={this.handleChange} />
36 </div>
37
38 </form>
39 )
40 }
41}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected