mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
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:
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user