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 🙏

© 2024 – Pkg Stats / Ryan Hefner

notion-react

v1.0.0

Published

Easily map Notion blocks to React components, completely customizable and type-safe.

Downloads

3

Readme

Notion React

Notion React allows you to easily map Notion components to your React projects, while completely maintaining customizability to make the components look and behave however you want.

Installation

Use the following command in the root directory of your React project to install the dependency.

npm i notion-react

Important Notes

This library is based around the data structure of the @notionhq/client package, the block list response structure from this library should be used to map components.

Usage

To create a NotionRenderer, which is what we use to map React components to Notion blocks, we can use the makeNotionRenderer function.

You can do this outside the body of the component that will be containing the Notion content.

Then, you can simply pass the components you'd like to map into the convenient, type-safe makeNotionRenderer function.

// Example.tsx

import NotionHeading from "@/components/NotionHeading";
import makeNotionRenderer, { NotionAPIBlockList } from "notion-react";

const { NotionRenderer } = makeNotionRenderer({
  heading_1: NotionHeading,
});

interface ExampleProps {
  blocks: NotionAPIBlockList;
}

const Example: React.FC<ExampleProps> = ({ blocks }) => {
  return <NotionRenderer blocks={blocks} />;
};

export default Example;

We will also need to create our type-safe NotionHeading component, which is what we mapped the heading_1 component to.

// NotionHeading.tsx

import { NotionBlockComponent, NotionBlock } from "notion-react";

const NotionHeading: NotionBlockComponent<NotionBlock.HEADING_1> = (
	props
) => {
  const [text] = props.heading_1.rich_text;
  const { plain_text } = text;
  return <h1>{plain_text}</h1>;
};

export default NotionHeading;

✨ Bam! Just like that, we have an easy-to-use, type-safe Notion renderer that is FULLY customizable, no default style-overriding shenanigans.

Now every time a heading_1 block appears on the Notion page that the block is originating from, it will appear on our page as the NotionHeading component we created.