Todo app built with vanilla JavaScript
Design comparison
Solution retrospective
Anyone know how to save the task list to local storage? I try to save it and get it but when I got the item, it turned out to [object object]. pls help :)
Community feedback
- @iliwiliPosted about 3 years ago
Hey, first of all, I really like how your solution looks and works.
For the localStorage problem you have. Your code at the moment doesn't let you do what you want because of your
render
method.if (leadsFromLocalStorage) { todoLists = leadsFromLocalStorage; render(todoLists); }
You pass down a list in your method
render(lists)
, but you don't loop through the list in thisrender
method. This method just appends one element in yourlist-container
. That doesn't mean yourrender
method is incorrect, it just means you need to tackle it in a different way.1st way
const renderItem = (value, checked) => {} if (leadsFromLocalStorage) { todoLists = leadsFromLocalStorage; todoLists.forEach((todo) => { render(todo.value, todo.checked); }); }
Change the render method to something like 'renderItem' and it should have 2 parameters: 'value' and 'checked', then assign the
value
andchecked
to the right HTML elements. After that you need to loop through the todoLists list and render each item as shown in the code above.2d way
You change how the 'render' method functions, you get the list as a parameter and re-render the whole list every time something happens. So you clear the container-list div and re-render the whole list.
I personally would recommend the first way, because it is more efficient and you don't need to change too much functionality.
Hope this helps! :)
Marked as helpful2@ZulfaabamPosted about 3 years ago@iliwili OMG dude, that really does the job. Thank you so much mannn.
1
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord