1Local Storage is key-value storage where key is string and value is string also.
2
3You must stringify your data, you can do this
4
5localStorage.setItem('user', JSON.stringify(user));
6
7
8And get it like
9
10const user = JSON.parse(localStorage.getItem('user'));
11
1localStorage.setItem('myCat', 'Tom');
2
3var cat = localStorage.getItem('myCat');
4
5localStorage.removeItem('myCat');
6
7// Clear all items
8localStorage.clear();
9
1// setter
2localStorage.setItem('myData', data);
3// getter
4localStorage.getItem('myData');
5// remove
6localStorage.removeItem('myData');
7// remove all
8localStorage.clear();
1handleFormSubmit = () => {
2 const { user, rememberMe } = this.state;
3 localStorage.setItem('rememberMe', rememberMe);
4 localStorage.setItem('user', rememberMe ? user : '');
5};