Answers for "react save to local storage"

5

save to local storage

localStorage.setItem('myCat', 'Tom');

var cat = localStorage.getItem('myCat');

localStorage.removeItem('myCat');

// Clear all items
localStorage.clear();
Posted by: Guest on April-27-2020
3

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'));
Posted by: Guest on October-14-2020
17

react localstorage

// setter
localStorage.setItem('myData', data);
// getter
localStorage.getItem('myData');
// remove
localStorage.removeItem('myData');
// remove all
localStorage.clear();
Posted by: Guest on February-21-2020
1

react save to local storage

handleFormSubmit = () => {
  const { user, rememberMe } = this.state;
  localStorage.setItem('rememberMe', rememberMe);
  localStorage.setItem('user', rememberMe ? user : '');
};
Posted by: Guest on September-01-2021
0

save to local storage

var cat = localStorage.getItem('myCat');
Posted by: Guest on April-27-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language