mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 20:27:44 +00:00
chore: update to Fumadocs 15.7 (#4154)
Co-authored-by: KinfeMichael Tariku <65047246+Kinfe123@users.noreply.github.com> Co-authored-by: Kinfe123 <kinfishtech@gmail.com>
This commit is contained in:
31
docs/components/ui/use-copy-button.tsx
Normal file
31
docs/components/ui/use-copy-button.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
"use client";
|
||||
import { type MouseEventHandler, useEffect, useRef, useState } from "react";
|
||||
import { useEffectEvent } from "fumadocs-core/utils/use-effect-event";
|
||||
|
||||
export function useCopyButton(
|
||||
onCopy: () => void | Promise<void>,
|
||||
): [checked: boolean, onClick: MouseEventHandler] {
|
||||
const [checked, setChecked] = useState(false);
|
||||
const timeoutRef = useRef<number | null>(null);
|
||||
|
||||
const onClick: MouseEventHandler = useEffectEvent(() => {
|
||||
if (timeoutRef.current) window.clearTimeout(timeoutRef.current);
|
||||
const res = Promise.resolve(onCopy());
|
||||
|
||||
void res.then(() => {
|
||||
setChecked(true);
|
||||
timeoutRef.current = window.setTimeout(() => {
|
||||
setChecked(false);
|
||||
}, 1500);
|
||||
});
|
||||
});
|
||||
|
||||
// Avoid updates after being unmounted
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (timeoutRef.current) window.clearTimeout(timeoutRef.current);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return [checked, onClick];
|
||||
}
|
||||
Reference in New Issue
Block a user