npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mzebley/mark-down-react

v1.2.2

Published

mark↓ React Adapter

Downloads

388

Readme

mark↓ React Adapter

(published as @mzebley/mark-down-react)

React bindings for the mark↓ core runtime. This package exposes context providers, hooks, and ready-to-use components that make it simple to render Markdown snippets safely. For a broader overview of the project, start with the root README.

Table of contents

  1. Installation
  2. Provider setup
  3. Hook
  4. <SnippetView /> component
  5. Server-side rendering
  6. TypeScript helpers
  7. Roadmap
  8. Related packages

Installation

Install the adapter along with the core runtime and DOMPurify (used for sanitising HTML):

npm install @mzebley/mark-down-react @mzebley/mark-down dompurify

Generate a manifest with the CLI before rendering snippets.

Provider setup

Wrap your app with the SnippetProvider so that hooks and components can access a shared client instance:

import { SnippetProvider } from '@mzebley/mark-down-react';

export function App({ children }: { children: React.ReactNode }) {
  return (
    <SnippetProvider options={{ manifest: '/snippets-index.json' }}>
      {children}
    </SnippetProvider>
  );
}

options maps directly to the SnippetClient configuration, so you can provide custom fetch functions, base paths, or preloaded manifest arrays as needed.

Hook

useSnippet(slug)

Fetch a single snippet and track loading / error state:

import { useSnippet } from '@mzebley/mark-down-react';

export function Hero() {
  const { snippet, loading, error } = useSnippet('getting-started-welcome');

  if (loading) return <p>Loading…</p>;
  if (error) return <p role="alert">Failed to load snippet.</p>;
  if (!snippet) return null;

  return <div dangerouslySetInnerHTML={{ __html: snippet.html }} />;
}

<SnippetView /> component

Render snippets declaratively with built-in loading and error fallbacks:

import { SnippetView } from '@mzebley/mark-down-react';

<SnippetView
  slug="components-button"
  loadingFallback={<p>Loading…</p>}
  errorFallback={<p role="alert">Unable to load snippet.</p>}
  onLoaded={(snippet) => console.log('Rendered', snippet.slug)}
/>;

Features:

  • Uses DOMPurify under the hood for HTML sanitisation.
  • Accepts className for styling and emits onLoaded(snippet) once HTML resolves.
  • Customise UX via loadingFallback / errorFallback, or render the hook directly for complete control.

Server-side rendering

When using Next.js, Remix, or another SSR framework, provide a server-safe fetch implementation:

import fetch from 'node-fetch';
import { SnippetProvider } from '@mzebley/mark-down-react';

<SnippetProvider
  options={{
    manifest: () => import('../snippets-index.json'),
    fetch: (url) => fetch(url).then((response) => {
      if (!response.ok) {
        throw new Error(`Request failed with status ${response.status}`);
      }
      return response;
    }),
  }}
>
  {children}
</SnippetProvider>;

Because the adapter defers to the core runtime, SSR works the same way as the base client. Pair with framework-specific data fetching if you prefer to prehydrate snippets.

TypeScript helpers

All exported hooks and components ship with rich TypeScript definitions:

  • Use the Snippet and SnippetMeta types from @mzebley/mark-down to annotate props.
  • Narrow snippet metadata with generics: useSnippet<CustomExtra>('slug').
  • Leverage the SnippetContextValue interface when mocking providers in tests.

Roadmap

  • Collection hooks – add useSnippets for list queries and pagination helpers for design system docs.
  • Suspense support – optional wrappers that expose a resource-style API for React 18 concurrent features.
  • Custom sanitizers – let consumers inject DOMPurify configs or alternate HTML sanitizers.
  • Storybook plugin – surface snippets inside Storybook/Chromatic panels for quick previews.

Related packages