File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change 11import React , { Component , PropTypes } from 'react' ;
22
33export default class AddTodo extends Component {
4- handleClick ( ) {
4+ handleSubmit ( e ) {
5+ e . preventDefault ( ) ;
56 const node = this . refs . input ;
67 const text = node . value . trim ( ) ;
7- this . props . onAddClick ( text ) ;
8- node . value = '' ;
8+ if ( text ) {
9+ this . props . onAddSubmit ( text ) ;
10+ node . value = '' ;
11+ }
912 }
1013
1114 render ( ) {
1215 return (
1316 < div >
14- < input type = "text" ref = "input" />
15- < button onClick = { ( e ) => this . handleClick ( e ) } >
16- Add
17- </ button >
17+ < form onSubmit = { ( e ) => this . handleSubmit ( e ) } >
18+ < input type = "text" ref = "input" />
19+ < button >
20+ Add
21+ </ button >
22+ </ form >
1823 </ div >
1924 ) ;
2025 }
2126}
2227
2328AddTodo . propTypes = {
24- onAddClick : PropTypes . func . isRequired
29+ onAddSubmit : PropTypes . func . isRequired
2530} ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class App extends Component {
1212 return (
1313 < div >
1414 < AddTodo
15- onAddClick = { text => dispatch ( addTodo ( text ) ) } />
15+ onAddSubmit = { text => dispatch ( addTodo ( text ) ) } />
1616 < TodoList
1717 todos = { visibleTodos }
1818 onTodoClick = { index => dispatch ( completeTodo ( index ) ) } />
You can’t perform that action at this time.
0 commit comments