/* * This is used to wrap a Table of Contents (toc) as returned * from the mdxLoader method (see shared/mdx/loader.js) * It is NOT for wrapping plain markdown/mdx */ import { useState, useEffect, Fragment } from 'react' // See: https://mdxjs.com/guides/mdx-on-demand/ import { run } from '@mdx-js/mdx' import * as runtime from 'react/jsx-runtime' const TocWrapper = ({ toc, app }) => { const [mdxModule, setMdxModule] = useState() useEffect(() => { ;(async () => { // Workaround for issue introduced in MDX 2.2 setMdxModule(await run(toc, { ...runtime, jsxDEV: runtime.jsx })) })() }, [toc]) // React component for MDX content const MdxContent = mdxModule ? mdxModule.default : Fragment // Don't render an empty toc const children = typeof MdxContent === 'function' ? MdxContent().props.children : false return children ? (