Skip to content

Commit 563d7c2

Browse files
committed
submit form ToDo examples and docs
1 parent 4266ed6 commit 563d7c2

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

docs/basics/ExampleTodoList.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,21 @@ let AddTodo = ({ dispatch }) => {
347347

348348
return (
349349
<div>
350-
<input ref={node => {
351-
input = node
352-
}} />
353-
<button onClick={() => {
350+
<form onSubmit={e => {
351+
e.preventDefault()
352+
if (!input.value.trim()) {
353+
return
354+
}
354355
dispatch(addTodo(input.value))
355356
input.value = ''
356357
}}>
357-
Add Todo
358-
</button>
358+
<input ref={node => {
359+
input = node
360+
}} />
361+
<button type="submit">
362+
Add Todo
363+
</button>
364+
</form>
359365
</div>
360366
)
361367
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ let AddTodo = ({ dispatch }) => {
99
<div>
1010
<form onSubmit={e => {
1111
e.preventDefault()
12-
if (input.value.trim()) {
13-
dispatch(addTodo(input.value))
12+
if (!input.value.trim()) {
13+
return
1414
}
15+
dispatch(addTodo(input.value))
1516
input.value = ''
1617
}}>
1718
<input ref={node => {

examples/todos/containers/AddTodo.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ let AddTodo = ({ dispatch }) => {
99
<div>
1010
<form onSubmit={e => {
1111
e.preventDefault()
12-
if (input.value.trim()) {
13-
dispatch(addTodo(input.value))
12+
if (!input.value.trim()) {
13+
return
1414
}
15+
dispatch(addTodo(input.value))
1516
input.value = ''
1617
}}>
1718
<input ref={node => {

0 commit comments

Comments
 (0)