@erosnicolau/animated-text
Version:
Advanced React animated text component with comprehensive animation effects
35 lines (34 loc) • 1.26 kB
JavaScript
/**
* Reactive hook for performance mode state that updates across all components
*/
import { useEffect, useState } from 'react';
const getPerformanceModeState = () => {
try {
return localStorage.getItem('fps-performance-mode') === 'true';
}
catch {
return false;
}
};
export const usePerformanceModeState = () => {
const [isPerformanceModeActive, setIsPerformanceModeActive] = useState(getPerformanceModeState);
useEffect(() => {
const handleStorageChange = (e) => {
if (e.key === 'fps-performance-mode') {
setIsPerformanceModeActive(e.newValue === 'true');
}
};
// Listen for storage events (both from localStorage changes and our custom dispatch)
window.addEventListener('storage', handleStorageChange);
// Also poll every second to catch programmatic changes
const interval = setInterval(() => {
const currentState = getPerformanceModeState();
setIsPerformanceModeActive(currentState);
}, 1000);
return () => {
window.removeEventListener('storage', handleStorageChange);
clearInterval(interval);
};
}, []);
return isPerformanceModeActive;
};