Skip to content

Fixes Todo-List Local Storage Issue (fixes #205)#206

Closed
ankyie wants to merge 2 commits intoCodeWithHarry:mainfrom
ankyie:main
Closed

Fixes Todo-List Local Storage Issue (fixes #205)#206
ankyie wants to merge 2 commits intoCodeWithHarry:mainfrom
ankyie:main

Conversation

@ankyie
Copy link

@ankyie ankyie commented Jul 24, 2024

The function saveToLS was getting executed properly due to the asynchronous nature of useState() function. This was fixed by initializing the Todo List (todos) using a function called GetTodos(). Initializing with a seperate function ensures 2 things:

  1. The useEffect function used later on; which tracks todos, does not get interfered by todos getting initialized with the help of settodos(). This ensures that the local storage during initialization remains intact while also always listening to any changes made in todos after initialization. Hence, the fetching from local storage remains the same, but made in a different way.
  2. This enables the use of useEffect() on todos, and removes the need to add "saveToLS()" everywhere the list changes. This also keeps track of todo_list LIVE, instead of some change/function triggering saveToLS() directly/indirectly.

@ankyie
Copy link
Author

ankyie commented Jul 24, 2024

This fixes the local storage bug from #205

@ankyie ankyie closed this Jul 24, 2024
@sayanoops
Copy link

thanks a lot bro I had been struggling with this problem for few hours and now the issue is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants