@mdx-js/react
Advanced tools
Comparing version 2.0.0-rc.2 to 2.0.0
@@ -68,11 +68,16 @@ /** | ||
const contextComponents = React.useContext(MDXContext) | ||
// Memoize to avoid unnecessary top-level context changes | ||
return React.useMemo(() => { | ||
// Custom merge via a function prop | ||
if (typeof components === 'function') { | ||
return components(contextComponents) | ||
} | ||
// Custom merge via a function prop | ||
if (typeof components === 'function') { | ||
return components(contextComponents) | ||
} | ||
return {...contextComponents, ...components} | ||
return {...contextComponents, ...components} | ||
}, [contextComponents, components]) | ||
} | ||
/** @type {Components} */ | ||
const emptyObject = {} | ||
/** | ||
@@ -88,3 +93,3 @@ * Provider for MDX context | ||
if (disableParentContext) { | ||
allComponents = components || {} | ||
allComponents = components || emptyObject | ||
} | ||
@@ -91,0 +96,0 @@ |
{ | ||
"name": "@mdx-js/react", | ||
"version": "2.0.0-rc.2", | ||
"version": "2.0.0", | ||
"description": "React context for MDX", | ||
@@ -51,7 +51,7 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@mdx-js/mdx": "^2.0.0-rc.2", | ||
"@mdx-js/mdx": "^2.0.0", | ||
"@types/react": "^17.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"react": "^18.0.0-alpha-327d5c484-20211106", | ||
"react-dom": "^18.0.0-alpha-327d5c484-20211106" | ||
"react": "^18.0.0-beta-24dd07bd2-20211208", | ||
"react-dom": "^18.0.0-beta-24dd07bd2-20211208" | ||
}, | ||
@@ -62,3 +62,3 @@ "scripts": { | ||
"test-api": "node --no-warnings --experimental-loader=../../script/jsx-loader.js ../../node_modules/uvu/bin.js test \"\\.jsx?$\"", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run test-coverage" | ||
@@ -65,0 +65,0 @@ }, |
@@ -39,7 +39,4 @@ # `@mdx-js/react` | ||
This package is not needed for MDX to work with React. | ||
But it is nice if you enjoy context-based props passing to avoid repetition. | ||
This package adds support for a React context based interface to set components | ||
(sometimes known as *shortcodes*) by passing them to an `MDXProvider`, which | ||
then are used in all nested MDX files implicitly. | ||
The alternative is to pass those components to each MDX file. | ||
See [¶ MDX provider in § Using MDX][use-provider] for when and how to use an MDX | ||
provider. | ||
@@ -54,3 +51,3 @@ ## Install | ||
```sh | ||
npm install @mdx-js/react@next | ||
npm install @mdx-js/react | ||
``` | ||
@@ -61,3 +58,3 @@ | ||
```sh | ||
yarn add @mdx-js/react@next | ||
yarn add @mdx-js/react | ||
``` | ||
@@ -69,3 +66,7 @@ | ||
import {MDXProvider} from '@mdx-js/react' | ||
import Post from './post.mdx' // Assumes an integration is used to compile MDX -> JS. | ||
import Post from './post.mdx' | ||
// ^-- Assumes an integration is used to compile MDX to JS, such as | ||
// `@mdx-js/esbuild`, `@mdx-js/loader`, `@mdx-js/node-loader`, or | ||
// `@mdx-js/rollup`, and that it is configured with | ||
// `options.providerImportSource: '@mdx-js/react'`. | ||
@@ -218,3 +219,3 @@ const components = { | ||
[coc]: https://github.com/mdx-js/.github/blob/HEAD/code-of-conduct.md | ||
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md | ||
@@ -229,3 +230,3 @@ [mit]: https://github.com/mdx-js/mdx/blob/main/packages/react/license | ||
[use-provider]: https://mdxjs.com/using-mdx/#mdx-provider | ||
[use-provider]: https://mdxjs.com/docs/using-mdx/#mdx-provider | ||
@@ -232,0 +233,0 @@ [security]: https://mdxjs.com/getting-started/#security |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
14000
157
0
230