File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,18 @@ const App = () => {
2323 const [ todos , setTodos ] = useState ( initalTodos ) ;
2424 const [ task , setTask ] = useState ( '' ) ;
2525
26+ const handleChangeCheckbox = id => {
27+ setTodos (
28+ todos . map ( todo => {
29+ if ( todo . id === id ) {
30+ return { ...todo , complete : ! todo . complete } ;
31+ } else {
32+ return todo ;
33+ }
34+ } )
35+ ) ;
36+ } ;
37+
2638 const handleChangeInput = event => {
2739 setTask ( event . target . value ) ;
2840 } ;
@@ -42,7 +54,14 @@ const App = () => {
4254 < ul >
4355 { todos . map ( todo => (
4456 < li key = { todo . id } >
45- < label > { todo . task } </ label >
57+ < label >
58+ < input
59+ type = "checkbox"
60+ checked = { todo . complete }
61+ onChange = { ( ) => handleChangeCheckbox ( todo . id ) }
62+ />
63+ { todo . task }
64+ </ label >
4665 </ li >
4766 ) ) }
4867 </ ul >
You can’t perform that action at this time.
0 commit comments