Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

next-mdx-remote

Package Overview
Dependencies
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-mdx-remote

utilities for loading mdx from any remote source as data, rather than as a local import

  • 5.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
206K
decreased by-5.35%
Maintainers
4
Weekly downloads
 
Created

What is next-mdx-remote?

The next-mdx-remote package allows you to use MDX (Markdown with JSX) in a Next.js application. It enables server-side rendering of MDX content, making it possible to dynamically load and render MDX files at runtime.

What are next-mdx-remote's main functionalities?

Server-side rendering of MDX

This feature allows you to serialize MDX content on the server side and then render it on the client side using the MDXRemote component.

const { serialize } = require('next-mdx-remote/serialize');
const { MDXRemote } = require('next-mdx-remote');

export async function getStaticProps() {
  const source = 'Some **MDX** content';
  const mdxSource = await serialize(source);
  return { props: { mdxSource } };
}

export default function Page({ mdxSource }) {
  return <MDXRemote {...mdxSource} />;
}

Dynamic MDX content

This feature allows you to read MDX content from a file and render it dynamically in your Next.js application.

import { serialize } from 'next-mdx-remote/serialize';
import { MDXRemote } from 'next-mdx-remote';
import fs from 'fs';
import path from 'path';

export async function getStaticProps() {
  const filePath = path.join(process.cwd(), 'content', 'example.mdx');
  const source = fs.readFileSync(filePath, 'utf8');
  const mdxSource = await serialize(source);
  return { props: { mdxSource } };
}

export default function Page({ mdxSource }) {
  return <MDXRemote {...mdxSource} />;
}

Custom components in MDX

This feature allows you to define custom React components that can be used within your MDX content.

import { serialize } from 'next-mdx-remote/serialize';
import { MDXRemote } from 'next-mdx-remote';

const components = {
  h1: (props) => <h1 style={{ color: 'tomato' }} {...props} />,
};

export async function getStaticProps() {
  const source = '# Hello, world!';
  const mdxSource = await serialize(source);
  return { props: { mdxSource } };
}

export default function Page({ mdxSource }) {
  return <MDXRemote {...mdxSource} components={components} />;
}

Other packages similar to next-mdx-remote

Keywords

FAQs

Package last updated on 22 May 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc