import * as runtime from "react/jsx-runtime"
import Image from "next/image"
import { Callout } from "./callout"
const useMDXComponent = (code: string) => {
const fn = new Function(code)
return fn({ ...runtime }).default
}
const components = {
Image,
Callout,
}
type MdxProps = {
code: string
}
export function MDXContent({ code }: Readonly<MdxProps>) {
const Component = useMDXComponent(code)
return <Component components={{ ...components }} />
}
I have this code to render the MDX following the documentation but since I upgraded to nextjs 16 with react 19.2 I have this error:
Error: Cannot create components during render
Components created during render will reset their state each time they are created. Declare components outside of render.
/home/mrguga/Workplace/my-portfolio/components/mdx-content.tsx:23:11
21 | const Component = useMDXComponent(code)
22 |
> 23 | return <Component components={{ ...components }} />
| ^^^^^^^^^ This component is created during render
24 | }
25 |
/home/mrguga/Workplace/my-portfolio/components/mdx-content.tsx:21:21
19 |
20 | export function MDXContent({ code }: Readonly<MdxProps>) {
> 21 | const Component = useMDXComponent(code)
| ^^^^^^^^^^^^^^^^^^^^^ The component is created during render here
22 |
23 | return <Component components={{ ...components }} />
24 | }eslint(react-hooks/static-components)
How can I solve this in a clean way?
And I recognised that Component returned from useMDXComponent is of type any can it be more declarative?
I have this code to render the MDX following the documentation but since I upgraded to nextjs 16 with react 19.2 I have this error:
How can I solve this in a clean way?
And I recognised that Component returned from useMDXComponent is of type any can it be more declarative?