File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -48,20 +48,22 @@ const Demo = () => {
48
48
setNewTodo ( e . target . value ) ;
49
49
} ;
50
50
51
- const onCompleteTodo = ( e : any , sqlId : number ) => {
51
+ const onCompleteTodo = (
52
+ e : React . ChangeEvent < HTMLInputElement > ,
53
+ sqlId : number
54
+ ) => {
52
55
const { id, checked } = e . target ;
53
56
const newTodos = todos ;
54
57
const todo = todos . find ( ( todo ) => todo . id === sqlId ) ;
55
58
56
- if ( todo ) {
57
- todo [ id as keyof Todo ] = checked as never ;
59
+ if ( todo && id === 'completed' ) {
60
+ onUpdateTodo ( sqlId , checked , id ) . then ( ( res ) => {
61
+ if ( res ?. status === 200 ) {
62
+ todo [ id ] = checked ;
63
+ setTodos ( [ ...newTodos ] ) ;
64
+ }
65
+ } ) ;
58
66
}
59
-
60
- onUpdateTodo ( sqlId , checked , id ) . then ( ( res ) => {
61
- if ( res ?. status === 200 ) {
62
- setTodos ( [ ...newTodos ] ) ;
63
- }
64
- } ) ;
65
67
} ;
66
68
67
69
const onSubmitCreateTodo = async ( e : React . FormEvent ) => {
@@ -246,7 +248,7 @@ const Demo = () => {
246
248
< TableCell style = { { textAlign : 'center' } } >
247
249
< Checkbox
248
250
checked = { todo . completed }
249
- onClick = { ( e ) => onCompleteTodo ( e , todo . id ) }
251
+ onChange = { ( e ) => onCompleteTodo ( e , todo . id ) }
250
252
id = "completed"
251
253
/>
252
254
</ TableCell >
You can’t perform that action at this time.
0 commit comments