QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Retrieve Item from localStorage

Retrieves a value from localStorage by key and parses it.

  • localstorage
  • storage

Install

npx shadcn@latest add https://quicksnip.dev/r/retrieve-item-from-localstorage.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

const getFromLocalStorage = (key) => {
  const item = localStorage.getItem(key);
  return item ? JSON.parse(item) : null;
};

Usage

getFromLocalStorage('user'); // Returns: { name: 'John', age: 30 }