UNPKG

next-mdxlayer

Version:

Next.js plugin to integrate mdxlayer CLI and generated content

13 lines (10 loc) 510 B
import React from 'react'; import * as jsxRuntime from 'react/jsx-runtime'; import ReactDOM from 'react-dom'; const getMDXComponent = (code, globals = {}) => { const scope = { React, ReactDOM, ...globals }; const fn = new Function("jsxRuntime", ...Object.keys(scope), code); return fn(jsxRuntime, ...Object.values(scope)).default; }; const useMDXComponent = (code = "", globals = {}) => React.useMemo(() => getMDXComponent(code, globals), [code, globals]); export { getMDXComponent, useMDXComponent };