'use client'; // Read the persistent player preferences (volume, muted). useSyncExternalStore // over preferencesStore — re-renders when localStorage changes (same tab or // other tab via the native `storage` event). import { useSyncExternalStore } from 'react'; import { getPreferences, subscribePreferences, type PlayerPreferences, } from '../store/preferencesStore'; const SSR: PlayerPreferences = { volume: 1, muted: false }; function getServerSnapshot(): PlayerPreferences { return SSR; } export function usePlayerPreferences(): PlayerPreferences { return useSyncExternalStore(subscribePreferences, getPreferences, getServerSnapshot); }