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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@notionhq/custom-blocks

v0.1.8

Published

> [!NOTE] > **Pre-release.** Custom blocks are in private alpha. Breaking changes may land at any time.

Downloads

5,646

Readme

@notionhq/custom-blocks

[!NOTE] Pre-release. Custom blocks are in private alpha. Breaking changes may land at any time.

SDK for building Notion custom blocks.

A custom block runs as a sandboxed <iframe> inside the Notion app that has no direct access to the internet. The only channel between your block and Notion is a local postMessage bridge. This library implements the sandbox side of the bridge protocol and wraps it in a framework-neutral TypeScript API (@notionhq/custom-blocks) and typed React hooks (@notionhq/custom-blocks/react).

Install

Create a worker project with ntn workers new --template custom and use the dependencies and entrypoint it generates. In this repository, fixtures depend on the SDK through the workspace. React is optional unless the block imports @notionhq/custom-blocks/react. React blocks need react and react-dom.

For local preview, run ntn customblocks dev from the worker project, then open http://localhost:9873.

Quick start

Declare your custom block along with the rest of your worker definition:

// src/index.ts
import { Worker } from "@notionhq/workers";

const worker = new Worker();
export default worker;

worker.customBlock("hello", {
  path: "./blocks/hello",
  command: "npx vite build",
});

In the block's entry point defined above, wrap your React code in <NotionCustomBlock> so the SDK connects with Notion before anything renders:

// blocks/hello/src/index.tsx
import "@notionhq/custom-blocks/nds.css";
import {
  NotionCustomBlock,
  NotionTokenScope,
} from "@notionhq/custom-blocks/react";
import ReactDOM from "react-dom/client";
import { App } from "./App";

ReactDOM.createRoot(document.getElementById("root")!).render(
  <NotionCustomBlock>
    <NotionTokenScope>
      <App />
    </NotionTokenScope>
  </NotionCustomBlock>,
);

Hooks can then read live content directly from Notion:

// blocks/hello/src/App.tsx
import { useBlockId } from "@notionhq/custom-blocks/react";

export function App() {
  const blockId = useBlockId();
  return <div className="app">Hello from {blockId}.</div>;
}
.app {
  color: var(--content-primary);
  background: var(--bg-base);
  padding: var(--spacing-12);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-12);
}

<NotionCustomBlock> runs the SDK ↔ host handshake (connectinitinitResult) and only mounts children once it resolves. Inside the wrapper, every hook returns non-nullable values — there's no separate gating component to write. It also runs useCustomBlockAutoResize for you by default; pass autoResize={false} to opt out.

Notion design tokens

The optional @notionhq/custom-blocks/nds.css stylesheet provides the colors, spacing, typography, borders, and other design tokens used by Notion. Import it once, then put token-consuming UI inside <NotionTokenScope> as shown above.

<NotionTokenScope> applies the display and contrast modes selected by the host, so variables such as --content-primary and --bg-base stay in sync with Notion automatically. Hosts that do not provide a contrast mode use standard contrast.

NotionTokenScopeProps has one required children prop.

The stylesheet is scoped rather than installed globally. Render portals inside <NotionTokenScope>, or wrap the portal container in another scope. Framework-neutral renderers can read the current appearance with customBlock.getTheme() and customBlock.getContrastMode(); see Block Location & Appearance.

Reference

API surface, one page per category. Import framework-neutral APIs from @notionhq/custom-blocks; import React hooks and components from @notionhq/custom-blocks/react. Hover docs in your editor cover the per-field detail; these pages cover usage shape and the gotchas.

  • docs/lifecycle.md<NotionCustomBlock>, useCustomBlockInit, initCustomBlock, customBlock.autoResize, NotInIframeError, useCustomBlockAutoResize. The handshake, the React wrapper, sizing.
  • docs/block-location.mduseBlockId, useParent, usePage, useTheme, and useContrastMode. Where the block sits and how to read the host's appearance.
  • docs/data-sources.mduseDataSource, useManifest, customBlock.getManifest, the row, property, and date-value types, plus a worked example.
  • docs/pages.mdpages.create / get / update / delete, parent variants (including the recommended data_source_key), property input shapes.
  • docs/users.mdusers.list / get, the NotionUser shape, paging.
  • docs/errors.md — request results, error format, error codes, retries, and initialization failures.
  • docs/deployment.md — worker-backed deploys, localhost self-hosted fallback, where the manifest comes from.
  • docs/vite-plugin.md — the notionCustomBlock() Vite plugin.

Forbidden APIs

No top-level navigation, window.open, or auth redirects. No direct network requests — cross-origin work goes through the host (and is exposed via SDK hooks).

Bridge protocol

The bridge speaks a versioned postMessage protocol, but block authors should use this package's public APIs rather than send bridge messages directly. @notionhq/custom-blocks-protocol and @notionhq/custom-blocks-host are internal workspace packages and are not available to block authors.