Files
medusa-store/www/apps/api-reference/components/MDXContent/Client/index.tsx
Shahed Nasser 4d632e7a5d docs: added tests for components in api-reference project (#14428)
* add tests (WIP)

* added test for h2

* finished adding tests

* fixes

* fixes

* fixes
2026-01-05 10:56:56 +02:00

50 lines
1.3 KiB
TypeScript

"use client"
import React from "react"
import { useEffect, useState } from "react"
import getCustomComponents from "../../MDXComponents"
import type { ScopeType } from "../../MDXComponents"
import { MDXRemote } from "next-mdx-remote"
import type { MDXRemoteProps, MDXRemoteSerializeResult } from "next-mdx-remote"
import { serialize } from "next-mdx-remote/serialize"
export type MDXContentClientProps = {
content: any
className?: string
} & Partial<MDXRemoteProps>
const MDXContentClient = ({
content,
className,
...props
}: MDXContentClientProps) => {
const [parsedContent, setParsedContent] = useState<MDXRemoteSerializeResult>()
useEffect(() => {
void serialize(content, {
mdxOptions: {
// A workaround for an error in next-mdx-remote
// more details in this issue:
// https://github.com/hashicorp/next-mdx-remote/issues/350
development: process.env.NEXT_PUBLIC_ENV === "development",
},
scope: props.scope,
}).then((output) => {
setParsedContent(output)
})
}, [content, props.scope])
return (
<div className={className}>
{parsedContent !== undefined && (
<MDXRemote
{...parsedContent}
components={getCustomComponents((props.scope as ScopeType) || {})}
/>
)}
</div>
)
}
export default MDXContentClient