UNPKG

next-mdx-remote-client

Version:

A wrapper of the `@mdx-js/mdx` for the `nextjs` applications in order to load MDX content. It is a fork of `next-mdx-remote`.

37 lines 1.39 kB
import { jsx as _jsx } from "react/jsx-runtime"; /** * Copyright (c) @talatkuyuk AKA @ipikuka * SPDX-License-Identifier: MPL-2.0 */ import { MDXProvider, useMDXComponents } from "@mdx-js/react"; import { runSync } from "../lib/run.js"; /** * "run"s the javascript code in the compiled source, and * returns the <Content /> component whether or not wrapped with the MDXProvider * in the domain of client side rendering (csr). */ export function hydrate({ compiledSource, frontmatter = {}, scope = {}, components, disableParentContext, }) { try { const { Content, mod } = runSync(compiledSource, { frontmatter, scope, mdxOptions: { useMDXComponents, }, }); const content = components ? ( // wrap the Content with the MDXProvider in order to customize the standard markdown components _jsx(MDXProvider, { components: components, disableParentContext: disableParentContext, children: _jsx(Content, {}) })) : ( // no need to wrap the Content with the MDXProvider since there is no custom component provided _jsx(Content, {})); return { content, mod }; } catch (error) { return { content: _jsx("div", { className: "mdx-empty" }), mod: {}, error: error, }; } } //# sourceMappingURL=hydrate.js.map