Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@mdx-js/react
Advanced tools
The @mdx-js/react package allows you to use MDX (Markdown for the component era) with React. MDX is a syntax that lets you seamlessly use JSX in your markdown documents. You can import components, such as interactive charts or alerts, and export metadata. This makes writing long-form content with React components a breeze.
Embedding JSX in Markdown
Allows embedding JSX directly in your markdown files, enabling the inclusion of React components within the content.
<MDXProvider><MyDocument /></MDXProvider>
Importing and using components in MDX
Enables the import and use of React components directly in MDX files, making it easy to integrate interactive or custom elements in markdown content.
import { Chart } from './components/Chart'
# My MDX document
Here's a chart component in my MDX document:
<Chart />
Using MDXProvider to customize components
Allows customization of standard markdown elements (like headings, paragraphs) with your own React components, providing a way to apply consistent styling or behavior across all markdown content.
import { MDXProvider } from '@mdx-js/react'
import { MyHeading, MyParagraph } from './MyComponents'
const components = {
h1: MyHeading,
p: MyParagraph
}
<MDXProvider components={components}>
<MyDocument />
</MDXProvider>
Similar to @mdx-js/react, remark-react allows you to render markdown as React components. However, it uses the remark parsing library and does not support the direct use of JSX within markdown.
react-markdown is another library that lets you render markdown content as React components. It supports plugins to extend its functionality but, unlike @mdx-js/react, does not allow for the embedding of JSX components directly within the markdown.
markdown-to-jsx compiles markdown into JSX but is more focused on simplicity and performance. It doesn't offer the same level of integration with React components or the ability to import and use components directly in markdown files as @mdx-js/react does.
@mdx-js/react
React context for MDX.
This package is a context based components provider for combining React with MDX.
This package is not needed for MDX to work with React. See ¶ MDX provider in § Using MDX for when and how to use an MDX provider.
If you use Next.js, do not use this.
Add an mdx-components.tsx
(in src/
or /
) file instead.
See Configuring MDX on nextjs.org
for more info.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install @mdx-js/react
In Deno with esm.sh
:
import {MDXProvider} from 'https://esm.sh/@mdx-js/react@3'
In browsers with esm.sh
:
<script type="module">
import {MDXProvider} from 'https://esm.sh/@mdx-js/react@3?bundle'
</script>
/**
* @import {MDXComponents} from 'mdx/types.js'
*/
import {MDXProvider} from '@mdx-js/react'
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'`.
/** @type {MDXComponents} */
const components = {
em(properties) {
return <i {...properties} />
}
}
console.log(
<MDXProvider components={components}>
<Post />
</MDXProvider>
)
👉 Note: you don’t have to use
MDXProvider
and can pass components directly:
-<MDXProvider components={components}> - <Post /> -</MDXProvider> +<Post components={components} />
See ¶ React in § Getting started for how to get started with MDX and React. See ¶ MDX provider in § Using MDX for how to use an MDX provider.
This package exports the identifiers MDXProvider
and
useMDXComponents
.
There is no default export.
MDXProvider(properties?)
Provider for MDX context.
properties
(Props
)
— configurationElement (JSX.Element
).
useMDXComponents(components?)
Get current components from the MDX Context.
components
(MDXComponents
from mdx/types.js
or MergeComponents
, optional)
— additional components to use or a function that creates themCurrent components (MDXComponents
from
mdx/types.js
).
MergeComponents
Custom merge function (TypeScript type).
components
(MDXComponents
from mdx/types.js
)
— current components from the contextAdditional components (MDXComponents
from
mdx/types.js
).
Props
Configuration for MDXProvider
(TypeScript type).
children
(ReactNode
from react
,
optional)
— childrencomponents
(MDXComponents
from mdx/types.js
or MergeComponents
, optional)
— additional components to use or a function that creates themdisableParentContext
(boolean
, default: false
)
— turn off outer component contextThis package is fully typed with TypeScript.
It exports the additional types MergeComponents
and
Props
.
For types to work, make sure the TypeScript JSX
namespace is typed.
This is done by installing and using the types of your framework, as in
@types/react
.
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, @mdx-js/react@^3
,
compatible with Node.js 16.
See § Security on our website for information.
See § Contribute on our website for ways to get started. See § Support for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
FAQs
React context for MDX
The npm package @mdx-js/react receives a total of 5,158,272 weekly downloads. As such, @mdx-js/react popularity was classified as popular.
We found that @mdx-js/react demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.