An Interest In:
Web News this Week
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
December 25, 2021 06:15 am GMT
Original Link: https://dev.to/deepakjaiswal/recatjs-crud-operations-using-local-storage-3ih2
RecatJS CRUD operations using Local Storage
many developers using localStorage for learning or some operation
like add to cart and store token or user information into the browser.
What is local Storage?
local storage is type of memory in our browser to save our data.
local storage storage limit is 5 MB.
local storage is our browser memory so we can store everything in our browser using javascript or ReactJS.
In HTML
<script>localStorage.setItem("key","value");localStorage.getItem("key");localStorage.removeItem("key");console.log(localStorage)</script>
In ReactJS
function App(){localStorage.setItem("key","value");const store=localStorage.getItem("key");localStorage.removeItem("key");console.log(localStorage)return(<div>{store}</div>)}
In many users questions how we store array of object in localStorage. here is the solution.
const data={name:"Deepak",address:"Allahabad"}localStorage.setItem("user",JSON.stringify(data))const user=JSON.parse(localStorage.getItem("user"))console.log(user)//it return {name :"Deepak", address :"Allahabad"}
Original Link: https://dev.to/deepakjaiswal/recatjs-crud-operations-using-local-storage-3ih2
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To