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 st…


This content originally appeared on DEV Community and was authored by Deepak

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"}


This content originally appeared on DEV Community and was authored by Deepak


Print Share Comment Cite Upload Translate Updates
APA

Deepak | Sciencx (2021-12-25T06:15:28+00:00) RecatJS CRUD operations using Local Storage. Retrieved from https://www.scien.cx/2021/12/25/recatjs-crud-operations-using-local-storage/

MLA
" » RecatJS CRUD operations using Local Storage." Deepak | Sciencx - Saturday December 25, 2021, https://www.scien.cx/2021/12/25/recatjs-crud-operations-using-local-storage/
HARVARD
Deepak | Sciencx Saturday December 25, 2021 » RecatJS CRUD operations using Local Storage., viewed ,<https://www.scien.cx/2021/12/25/recatjs-crud-operations-using-local-storage/>
VANCOUVER
Deepak | Sciencx - » RecatJS CRUD operations using Local Storage. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/25/recatjs-crud-operations-using-local-storage/
CHICAGO
" » RecatJS CRUD operations using Local Storage." Deepak | Sciencx - Accessed . https://www.scien.cx/2021/12/25/recatjs-crud-operations-using-local-storage/
IEEE
" » RecatJS CRUD operations using Local Storage." Deepak | Sciencx [Online]. Available: https://www.scien.cx/2021/12/25/recatjs-crud-operations-using-local-storage/. [Accessed: ]
rf:citation
» RecatJS CRUD operations using Local Storage | Deepak | Sciencx | https://www.scien.cx/2021/12/25/recatjs-crud-operations-using-local-storage/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.