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 de922334b7
commit b35caf24f2
@@ -92,11 +92,20 @@ const CopyValue: FC<{ value: string | number }> = ({ value }) =>
const copy = useCallback(() =>
{
const text = String(value);
const done = () => { setCopied(true); window.setTimeout(() => setCopied(false), 1000); };
if(navigator.clipboard?.writeText) navigator.clipboard.writeText(text).then(done).catch(() => done());
else done();
if(navigator.clipboard?.writeText) navigator.clipboard.writeText(text).then(() => setCopied(true)).catch(() => setCopied(true));
else setCopied(true);
}, [ 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 (
<div
role="button"