diff --git a/packages/react/index.js b/packages/react/index.js index 7888697bb..e686091e3 100644 --- a/packages/react/index.js +++ b/packages/react/index.js @@ -1,6 +1 @@ -export { - MDXContext, - MDXProvider, - useMDXComponents, - withMDXComponents -} from './lib/index.js' +export {MDXProvider, useMDXComponents} from './lib/index.js' diff --git a/packages/react/lib/index.js b/packages/react/lib/index.js index 31b919c13..3d0bc6693 100644 --- a/packages/react/lib/index.js +++ b/packages/react/lib/index.js @@ -1,6 +1,5 @@ /** * @typedef {import('mdx/types.js').MDXComponents} Components - * @typedef {import('react').Context} Context * @typedef {import('react').ReactNode} ReactNode */ @@ -24,42 +23,7 @@ import React from 'react' -/** - * @type {Context} - * @deprecated - * This export is marked as a legacy feature. - * That means it’s no longer recommended for use as it might be removed - * in a future major release. - * - * Please use `useMDXComponents` to get context based components and - * `MDXProvider` to set context based components instead. - */ -export const MDXContext = React.createContext({}) - -/** - * @param {import('react').ComponentType} Component - * Component. - * @deprecated - * This export is marked as a legacy feature. - * That means it’s no longer recommended for use as it might be removed - * in a future major release. - * - * Please use `useMDXComponents` to get context based components instead. - */ -export function withMDXComponents(Component) { - return boundMDXComponent - - /** - * @param {Record & {components?: Components | null | undefined}} props - * Props. - * @returns {JSX.Element} - * Element. - */ - function boundMDXComponent(props) { - const allComponents = useMDXComponents(props.components) - return React.createElement(Component, {...props, allComponents}) - } -} +const MDXContext = React.createContext({}) /** * Get current components from the MDX Context. diff --git a/packages/react/readme.md b/packages/react/readme.md index 1cca1338c..c1e32853d 100644 --- a/packages/react/readme.md +++ b/packages/react/readme.md @@ -21,8 +21,6 @@ React context for MDX. * [API](#api) * [`MDXProvider(props?)`](#mdxproviderprops) * [`useMDXComponents(components?)`](#usemdxcomponentscomponents) - * [`MDXContext`](#mdxcontext) - * [`withMDXComponents(Component)`](#withmdxcomponentscomponent) * [Types](#types) * [Security](#security) * [Contribute](#contribute) @@ -92,8 +90,8 @@ provider. ## API -This package exports the following identifiers: `MDXContext`, `MDXProvider`, -`useMDXComponents`, and `withMDXComponents`. +This package exports the following identifiers: `MDXProvider` and +`useMDXComponents`. There is no default export. ### `MDXProvider(props?)` @@ -135,25 +133,6 @@ Components`). `Components`. -### `MDXContext` - -> 🪦 **Deprecated**: This export is not recommended for use as it exposes -> internals which should be hidden. -> It might be removed in a future major release. -> Please use `useMDXComponents` to get context based components and -> `MDXProvider` to set context based components instead. - -The React Context for MDX (`React.Context`). - -### `withMDXComponents(Component)` - -> 🪦 **Deprecated**: This export is not recommended for use. -> It might be removed in a future major release. -> Please use `useMDXComponents` to get context based components instead. - -Create a HOC of `Components` which is given the current context based MDX -components. - ## Types This package is fully typed with [TypeScript][]. diff --git a/packages/react/test/index.jsx b/packages/react/test/index.jsx index b7feb718a..cff290c9a 100644 --- a/packages/react/test/index.jsx +++ b/packages/react/test/index.jsx @@ -5,7 +5,7 @@ import assert from 'node:assert/strict' import {test} from 'node:test' import {evaluate} from '@mdx-js/mdx' -import {MDXProvider, useMDXComponents, withMDXComponents} from '@mdx-js/react' +import {MDXProvider, useMDXComponents} from '@mdx-js/react' import React from 'react' import * as runtime_ from 'react/jsx-runtime' import {renderToString} from 'react-dom/server' @@ -17,10 +17,8 @@ const runtime = /** @type {RuntimeProduction} */ ( test('@mdx-js/react', async function (t) { await t.test('should expose the public api', async function () { assert.deepEqual(Object.keys(await import('@mdx-js/preact')).sort(), [ - 'MDXContext', 'MDXProvider', - 'useMDXComponents', - 'withMDXComponents' + 'useMDXComponents' ]) }) @@ -207,45 +205,4 @@ test('@mdx-js/react', async function (t) { ) } ) - - await t.test('should support `withComponents`', async function () { - const {default: Content} = await evaluate('# hi\n## hello', { - ...runtime, - useMDXComponents - }) - - // Unknown props. - // type-coverage:ignore-next-line - const With = withMDXComponents(function (props) { - // Unknown props. - // type-coverage:ignore-next-line - return props.children - }) - - // Bug: this should use the `h2` component too, logically? - // As `withMDXComponents` is deprecated, and it would probably be a breaking - // change, we can just remove it later. - assert.equal( - renderToString( - - } - }} - > - - } - }} - > - - - - ), - '

hi

\n

hello

' - ) - }) })