Skip to content

add hook to use local storage#12

Open
JasminePRA wants to merge 1 commit into
mainfrom
chore/add-hook-local-storage
Open

add hook to use local storage#12
JasminePRA wants to merge 1 commit into
mainfrom
chore/add-hook-local-storage

Conversation

@JasminePRA

Copy link
Copy Markdown
Contributor

Pull Request

Description

  • Provides three methods: getItem, setItem, and removeItem
  • Handles JSON parsing/stringifying automatically
  • Returns null for non-existent keys instead of throwing errors
import useLocalStorage from './hooks/useLocalStorage';

const MyComponent = () => {
  const { getItem, setItem, removeItem } = useLocalStorage();
  
  // Store complex objects
  setItem('user', { name: 'John', age: 30 });
  
  // Retrieve and auto-parse
  const user = getItem('user'); // Returns parsed object or null
  
  // Clean up
  removeItem('user');
};

Type of Change

  • feature: New feature
  • chore: Maintenance, dependency updates, or refactoring
  • test: Adding or improving tests
  • bug: Bug fix
  • docs: Documentation updates
  • Other (please specify):

Shortcut story

https://trello.com/c/KsoEtS2D/20-hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant