Skip to content

Releases: umarSiddique010/use-localstorage-hook

v2.0.0 - Reactive State & Cross-Tab Sync

20 Jun 10:09

Choose a tag to compare

🚀 Major Update: Reactive State Management

✨ New Features

  • Reactive State: getStore is now a reactive value that triggers re-renders automatically
  • Cross-Tab Synchronization: Changes in one tab instantly sync to all other open tabs
  • Enhanced Error Handling: Comprehensive error recovery with fallback behavior
  • Input Validation: Strict validation for storeName and initialData parameters
  • Storage Event Listeners: Real-time synchronization across browser windows

💥 Breaking Changes

  • getStore is no longer a function - it's now the actual reactive value
  • Migration Guide:
    • Before: const value = getStore()
    • After: const value = getStore

📈 Improvements

  • Better initialization logic prevents accidental data overwrites
  • More robust error handling with detailed console logging
  • Cleaner component re-render behavior
  • Memory cleanup with proper event listener removal

🔧 Technical Changes

  • Replaced function-based getStore() with useState reactive state
  • Added storage event listener for cross-tab communication
  • Enhanced error boundaries with try/catch blocks
  • Improved lifecycle management with useEffect cleanup

📦 Installation

npm install @mdus/use-localstorage-hook@2.0.0

🚀 Quick Example

const { getStore: theme, setStore: setTheme } = useLocalstorage("theme", "light");

// getStore is now reactive - no function call needed!
return <div className={theme}>Current theme: {theme}</div>;

📚 Documentation

Updated README with new usage patterns and cross-tab sync examples.

Full Changelog: v1.0.0...v2.0.0