Skip to content

Commit 9c19fbd

Browse files
authored
Merge pull request #312 from Andrey-Bazhanov/main
improve useMDXComponent return type
2 parents 37eb0fd + a248162 commit 9c19fbd

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/next-contentlayer/src/hooks/useMDXComponent.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { MDXComponents } from 'mdx/types'
12
// NOTE use ESM/CommonJS compat import here until resolved: https://github.com/facebook/react/issues/11503
23
import React from 'react'
34
// NOTE use ESM/CommonJS compat import here until resolved: https://github.com/facebook/react/issues/11503
@@ -13,12 +14,17 @@ import { _jsx_runtime } from './jsx-runtime.cjs'
1314
// See https://github.com/contentlayerdev/contentlayer/issues/162
1415
// import * as _jsx_runtime from 'react/jsx-runtime'
1516

16-
const getMDXComponent = (code: string, globals: Record<string, unknown> = {}): React.ComponentType<any> => {
17+
type MDXContentProps = {
18+
[props: string]: unknown
19+
components?: MDXComponents
20+
}
21+
22+
const getMDXComponent = (code: string, globals: Record<string, unknown> = {}): React.ComponentType<MDXContentProps> => {
1723
const scope = { React, ReactDOM, _jsx_runtime, ...globals }
1824
const fn = new Function(...Object.keys(scope), code)
1925
return fn(...Object.values(scope)).default
2026
}
2127

22-
export const useMDXComponent = (code: string, globals: Record<string, unknown> = {}): React.ComponentType<any> => {
28+
export const useMDXComponent = (code: string, globals: Record<string, unknown> = {}) => {
2329
return React.useMemo(() => getMDXComponent(code, globals), [code, globals])
2430
}

0 commit comments

Comments
 (0)