File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,12 @@ function App() {
1111 ] ;
1212 const [ todos , setTodos ] = useState ( seededTodos ) ;
1313
14- const addTodo = ( ) => {
14+ const addTodo = ( description , assigned ) => {
1515 if ( seededTodos . length > 0 ) {
1616 const newTodo = {
1717 rowNumber : todos . length + 1 ,
18- rowDescription : "New todo" ,
19- rowAssigned : "User Three" ,
18+ rowDescription : description ,
19+ rowAssigned : assigned ,
2020 } ;
2121 setTodos ( ( todos ) => [ ...todos , newTodo ] ) ;
2222 }
@@ -28,7 +28,7 @@ function App() {
2828 < div className = "card-header" > Your Todo's</ div >
2929 < div className = "card-body" >
3030 < TodoTable todos = { todos } />
31- < NewTodoForm />
31+ < NewTodoForm addTodo = { addTodo } />
3232 </ div >
3333 </ div >
3434 </ div >
Original file line number Diff line number Diff line change 11import { useState } from "react" ;
22
3- export default function NewTodoForm ( ) {
3+ export default function NewTodoForm ( props ) {
44 const [ description , setDescription ] = useState ( "" ) ;
55 const [ assigned , setAssigned ] = useState ( "" ) ;
66
7+ const submitTodo = ( ) => {
8+ if ( description !== "" && assigned !== "" ) {
9+ props . addTodo ( description , assigned ) ;
10+ setDescription ( "" ) ;
11+ setAssigned ( "" ) ;
12+ }
13+ } ;
14+
715 return (
816 < div className = "mt-5" >
917 < form >
@@ -27,7 +35,11 @@ export default function NewTodoForm() {
2735 value = { description }
2836 />
2937 </ div >
30- < button type = "button" className = "btn btn-primary mt-3" >
38+ < button
39+ type = "button"
40+ className = "btn btn-primary mt-3"
41+ onClick = { submitTodo }
42+ >
3143 Add ToDo
3244 </ button >
3345 </ form >
You can’t perform that action at this time.
0 commit comments