'use client'; import { useLocalStorage } from '@/hooks/useLocalStorage'; import { useState } from 'react'; interface UserSettings { theme: 'light' | 'dark'; notifications: boolean; language: string; } export default function TestLocalStoragePage() { // Test 1: Simple string value const [name, setName, removeName] = useLocalStorage('test-name', 'Guest'); // Test 2: Complex object const [settings, setSettings, removeSettings] = useLocalStorage( 'test-settings', { theme: 'light', notifications: true, language: 'en', } ); // Test 3: Array const [items, setItems, removeItems] = useLocalStorage('test-items', []); // Test 4: Number const [count, setCount, removeCount] = useLocalStorage('test-count', 0); const [newItem, setNewItem] = useState(''); return (

useLocalStorage Hook Test Page

Open DevTools (F12) → Application → Local Storage to see values update in real-time. Refresh the page to verify persistence.

{/* Test 1: String */}

Test 1: String Value

Current Name: {name}

setName(e.target.value)} placeholder="Enter your name" style={{ padding: '0.5rem', marginRight: '0.5rem' }} />

localStorage key: test-name

{/* Test 2: Complex Object */}

Test 2: Complex Object

Theme: {settings.theme}

localStorage key: test-settings

{/* Test 3: Array */}

Test 3: Array Value

Items ({items.length}):

    {items.map((item, index) => (
  • {item}{' '}
  • ))}
setNewItem(e.target.value)} onKeyPress={(e) => { if (e.key === 'Enter' && newItem.trim()) { setItems((prev) => [...prev, newItem.trim()]); setNewItem(''); } }} placeholder="Add new item" style={{ padding: '0.5rem', marginRight: '0.5rem' }} />

localStorage key: test-items

{/* Test 4: Number */}

Test 4: Number Value

Count: {count}

localStorage key: test-count

{/* Instructions */}

Verification Checklist:

  • ✓ Open DevTools → Application → Local Storage → http://localhost:3000
  • ✓ Interact with the controls above and watch localStorage update in real-time
  • ✓ Refresh the page (F5) - all values should persist
  • ✓ Check Console for hydration errors (there should be none)
  • ✓ Check Console for any errors (there should be none)
  • ✓ Verify TypeScript has no errors in your editor
); }