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 = () => {
4848 setNewTodo ( e . target . value ) ;
4949 } ;
5050
51- const onCompleteTodo = ( e : any , sqlId : number ) => {
51+ const onCompleteTodo = (
52+ e : React . ChangeEvent < HTMLInputElement > ,
53+ sqlId : number
54+ ) => {
5255 const { id, checked } = e . target ;
5356 const newTodos = todos ;
5457 const todo = todos . find ( ( todo ) => todo . id === sqlId ) ;
5558
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+ } ) ;
5866 }
59-
60- onUpdateTodo ( sqlId , checked , id ) . then ( ( res ) => {
61- if ( res ?. status === 200 ) {
62- setTodos ( [ ...newTodos ] ) ;
63- }
64- } ) ;
6567 } ;
6668
6769 const onSubmitCreateTodo = async ( e : React . FormEvent ) => {
@@ -246,7 +248,7 @@ const Demo = () => {
246248 < TableCell style = { { textAlign : 'center' } } >
247249 < Checkbox
248250 checked = { todo . completed }
249- onClick = { ( e ) => onCompleteTodo ( e , todo . id ) }
251+ onChange = { ( e ) => onCompleteTodo ( e , todo . id ) }
250252 id = "completed"
251253 />
252254 </ TableCell >
You can’t perform that action at this time.
0 commit comments