fix(furni-editor): clear CopyValue reset timer on unmount

Move the 'copied!' 1s reset into a useEffect with cleanup so the timer
can't fire setState after the component unmounts.
This commit is contained in:
simoleo89
2026-06-06 15:48:19 +02:00
parent 3d1f1103a3
commit 0af8c8932b
@@ -92,11 +92,20 @@ const CopyValue: FC<{ value: string | number }> = ({ value }) =>
const copy = useCallback(() => const copy = useCallback(() =>
{ {
const text = String(value); const text = String(value);
const done = () => { setCopied(true); window.setTimeout(() => setCopied(false), 1000); }; if(navigator.clipboard?.writeText) navigator.clipboard.writeText(text).then(() => setCopied(true)).catch(() => setCopied(true));
if(navigator.clipboard?.writeText) navigator.clipboard.writeText(text).then(done).catch(() => done()); else setCopied(true);
else done();
}, [ value ]); }, [ value ]);
// Reset the "copied!" flag after 1s, with cleanup so the timer never fires after unmount.
useEffect(() =>
{
if(!copied) return;
const handle = window.setTimeout(() => setCopied(false), 1000);
return () => window.clearTimeout(handle);
}, [ copied ]);
return ( return (
<div <div
role="button" role="button"