Skip to content

Instantly share code, notes, and snippets.

@anmolsukki
Created May 5, 2020 15:30
Show Gist options
  • Save anmolsukki/23c757b3240a79fc329f23c23c8158d0 to your computer and use it in GitHub Desktop.
Save anmolsukki/23c757b3240a79fc329f23c23c8158d0 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
class Storage extends Component {
setData = () => {
let obj = { name: "Anmol", age: "24", email: "[email protected]" };
localStorage.setItem("myData", JSON.stringify(obj));
};
getData = () => {
let data = localStorage.getItem("myData");
data = JSON.parse(data);
console.log(data.name);
};
render() {
return (
<div>
<button onClick={() => this.setState()}>Set Data</button>
<button onClick={() => this.getData()}>Set Data</button>
</div>
);
}
}
export default Storage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment