mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-27 09:46:25 +02:00
fix(react): Add cancelAnimationFrame cleanup in useEffect
- Add cleanup function to cancel animation frame on unmount - Prevents potential memory leaks and setState on unmounted component - Closes #1093
This commit is contained in:
parent
c2bd2bc935
commit
805eacb9fc
3 changed files with 18 additions and 5 deletions
|
|
@ -15,6 +15,14 @@ export function useApiKey(): UseApiKeyReturn {
|
|||
const [copied, setCopied] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
// Clear copied state after 2 seconds
|
||||
useEffect(() => {
|
||||
if (copied) {
|
||||
const timer = setTimeout(() => setCopied(false), 2000);
|
||||
return () => clearTimeout(timer);
|
||||
}
|
||||
}, [copied]);
|
||||
|
||||
useEffect(() => {
|
||||
// Load API key from localStorage
|
||||
const loadApiKey = () => {
|
||||
|
|
@ -41,9 +49,6 @@ export function useApiKey(): UseApiKeyReturn {
|
|||
if (success) {
|
||||
setCopied(true);
|
||||
toast.success("API key copied to clipboard");
|
||||
setTimeout(() => {
|
||||
setCopied(false);
|
||||
}, 2000);
|
||||
} else {
|
||||
toast.error("Failed to copy API key");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue