Home > Software engineering >  Why localStorage implementation is not working with my application?
Why localStorage implementation is not working with my application?

Time:06-09

I am trying to create a todo lister app with the implementation of localStorage. The data I am trying to save is saving but couldn't output it. Here is the sandbox for the code: 'https://codesandbox.io/s/todo-lister-c2cime?file=/app.js'

CodePudding user response:

Just move function out off window.addEventListener("load".. like this.

// window.addEventListener("load", function () {
//     todoItems = JSON.parse(localStorage.getItem("todoList"));
//     createTodo(todoItems);
// });
init();
function init() {
  todoItems = JSON.parse(localStorage.getItem("todoList"));
  createTodo(todoItems);
}

By the way, Your localStorage is fine. You can debuged by Press F12 then. enter image description here

CodePudding user response:

you need to know that localstorage only allows you access from your app itself. this is your application address. this is app address but when you inspect the codesandbox web site you can only see the localstorage of codesandbox. this is localstorage when you inspect with codesandbox


  • Related