AmmarMohammed01 / TaskLists

https://ammarmohammed01.github.io/TaskLists/
0 stars 0 forks source link

Complete Status #2

Closed AmmarMohammed01 closed 3 months ago

AmmarMohammed01 commented 3 months ago

Although we are saving the complete status in the JSON object, the website is not loading in the green complete color on initial load.

Fix issue: complete tasks should load in as green.

AmmarMohammed01 commented 3 months ago

Fixed it now. Earlier whenever we updated an element of an todo-object inside of the list, the list useEffect was not called. Therefore I had to create a [check, setCheck] useState to call a different useEffect that runs whenever it sees a change in check.

The initial check was set to false. But this only partially solved the problem. If you set multiple variables to a boolean state of true, it would not call the useEffect for check because it saw the value of check not changing (it just remained true, even though you were changing multiple different tasks to true). The way I solved this was to set the check useState to a number (start at 0) and then increment every time I made a change to any of the tasks. This way the useEffect is called every time any task's complete status is changed.