javascript save data to local storage
// Store
localStorage.lastname = "Smith";
// Retrieve
document.getElementById("result").innerHTML = localStorage.lastname;
// Remove
localStorage.removeItem("lastname");
javascript save data to local storage
// Store
localStorage.lastname = "Smith";
// Retrieve
document.getElementById("result").innerHTML = localStorage.lastname;
// Remove
localStorage.removeItem("lastname");
save data to local storage
//useEffect(function (){}, []) this hook takes function as its first argument and an array/dependency as
//which if the [] arrray is empty it runs once, meaning on initial render
useEffect(() => {
const previousData = JSON.parse(localStorage.getItem("Todos"));
setTodos(previousData);
},[])
//and if something changes in the dependency's value in this case inputText the function that is passed as the first argument runs each time
useEffect(() => {
localStorage.setItem('Todos', JSON.stringify(Todos));
}, [inputText])
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us