Skip to content

Commit 5af881e

Browse files
committed
Merge pull request #933 from tonyspiro/master
todo undo example - from click to on submit
2 parents 0b598b1 + 92105be commit 5af881e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
import React, { Component, PropTypes } from 'react';
22

33
export 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

2328
AddTodo.propTypes = {
24-
onAddClick: PropTypes.func.isRequired
29+
onAddSubmit: PropTypes.func.isRequired
2530
};

examples/todos-with-undo/containers/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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))} />

0 commit comments

Comments
 (0)