save locally in javascript

To save data locally in JavaScript, you can use the localStorage object provided by the Web Storage API. Here's an example of how to save a key-value pair locally:

index.tsx
// Storing data locally
localStorage.setItem('key', 'value');
62 chars
3 lines

You can also retrieve the stored value using the key:

index.tsx
// Retrieving data locally
const myValue = localStorage.getItem('key');
console.log(myValue); // This will output 'value'
122 chars
4 lines

Remember that the data stored in localStorage will persist even after the user closes the browser.

related categories

gistlibby LogSnag