diff --git a/components/blog/button-client.tsx b/components/blog/button-client.tsx index 22c3c09..c709260 100644 --- a/components/blog/button-client.tsx +++ b/components/blog/button-client.tsx @@ -2,12 +2,22 @@ import { useEffect, useRef } from 'react' -export function ClientButton({ children, onClick, ...props }: { children?: React.ReactNode; onClick?: string } & React.ButtonHTMLAttributes) { +export function ClientButton({ + children, + onClick, + ...props +}: { + children?: React.ReactNode + onClick?: ((event: React.MouseEvent) => void) | string +} & React.ButtonHTMLAttributes) { const btnRef = useRef(null) useEffect(() => { - if (typeof onClick === 'string' && btnRef.current) { + if (!btnRef.current) return + if (typeof onClick === 'string') { btnRef.current.onclick = onClick as any + } else if (typeof onClick === 'function') { + btnRef.current.onclick = (e: Event) => onClick(e as React.MouseEvent) } }, [onClick])