diff --git a/components/blog/button-client.tsx b/components/blog/button-client.tsx new file mode 100644 index 0000000..22c3c09 --- /dev/null +++ b/components/blog/button-client.tsx @@ -0,0 +1,19 @@ +'use client' + +import { useEffect, useRef } from 'react' + +export function ClientButton({ children, onClick, ...props }: { children?: React.ReactNode; onClick?: string } & React.ButtonHTMLAttributes) { + const btnRef = useRef(null) + + useEffect(() => { + if (typeof onClick === 'string' && btnRef.current) { + btnRef.current.onclick = onClick as any + } + }, [onClick]) + + return ( + + ) +} diff --git a/mdx-components.tsx b/mdx-components.tsx index 750c996..9991dca 100644 --- a/mdx-components.tsx +++ b/mdx-components.tsx @@ -1,4 +1,5 @@ import type { MDXComponents } from 'mdx/types' +import { ClientButton } from '@/components/blog/button-client' export function getMDXComponents(components: MDXComponents): MDXComponents { return { @@ -106,10 +107,9 @@ export function getMDXComponents(components: MDXComponents): MDXComponents { details: (props) =>
, summary: (props) => , - button: ({ children, onClick, ...props }) => ( - typeof onClick === 'string' - ? - ), + button: ({ children, onClick, ...props }) => { + const onClickString = typeof onClick === 'string' ? onClick : undefined + return {children} + }, } }