save to local storage
localStorage.setItem('myCat', 'Tom');
var cat = localStorage.getItem('myCat');
localStorage.removeItem('myCat');
// Clear all items
localStorage.clear();
save to local storage
localStorage.setItem('myCat', 'Tom');
var cat = localStorage.getItem('myCat');
localStorage.removeItem('myCat');
// Clear all items
localStorage.clear();
save data in local storage reactjs returns [object, object]
Local Storage is key-value storage where key is string and value is string also.
You must stringify your data, you can do this
localStorage.setItem('user', JSON.stringify(user));
And get it like
const user = JSON.parse(localStorage.getItem('user'));
react localstorage
// setter
localStorage.setItem('myData', data);
// getter
localStorage.getItem('myData');
// remove
localStorage.removeItem('myData');
// remove all
localStorage.clear();
react save to local storage
handleFormSubmit = () => {
const { user, rememberMe } = this.state;
localStorage.setItem('rememberMe', rememberMe);
localStorage.setItem('user', rememberMe ? user : '');
};
save to local storage
var cat = localStorage.getItem('myCat');
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