@erosnicolau/animated-text
Version:
Advanced React animated text component with comprehensive animation effects
30 lines (29 loc) • 1.04 kB
JavaScript
/**
* Reactive hook for virtualization state that updates across all components
*/
import { useEffect, useState } from 'react';
const getVirtualizationState = () => {
try {
const saved = localStorage.getItem('debug-virtualization-enabled');
return saved !== null ? saved === 'true' : true;
}
catch {
return true;
}
};
export const useVirtualizationState = () => {
const [isVirtualizationEnabled, setIsVirtualizationEnabled] = useState(getVirtualizationState);
useEffect(() => {
const handleStorageChange = (e) => {
if (e.key === 'debug-virtualization-enabled') {
setIsVirtualizationEnabled(e.newValue === 'true');
}
};
// Listen for storage events (both from localStorage changes and our custom dispatch)
window.addEventListener('storage', handleStorageChange);
return () => {
window.removeEventListener('storage', handleStorageChange);
};
}, []);
return isVirtualizationEnabled;
};