Notion Mapper is a lightweight, reusable React component library built with Vite and TypeScript to map and render Notion API blocks into a beautiful, customizable UI. Whether you're building a blog, documentation site, or any content-driven application using Notion as a CMS, this package simplifies the process of transforming Notion block data into responsive, Tailwind CSS-styled components.
- Full Notion Block Support: Render all Notion block types (paragraphs, headings, images, code, tables, callouts, and more).
- TypeScript Ready: Fully typed with comprehensive interfaces for Notion blocks.
- Tailwind CSS Styling: Modern, responsive design out of the box with Tailwind CSS.
- Vite-Powered: Fast development and optimized production builds.
- Modular Architecture: Easily extendable and reusable components.
- SEO Optimized: Clean, semantic HTML output for better search engine visibility.
Install react-notion-blocks via npm:
npm install react-notion-blocks
Or with Yarn:
yarn add react-notion-blocksimport { useEffect, useState } from "react";
import { NotionBlock, blockMapper } from "react-notion-blocks";
interface PageData {
id: string;
title: string;
content: NotionBlock[];
}
function App() {
const [page, setPage] = useState<PageData | null>(null);
useEffect(() => {
const fetchData = async () => {
const response = await fetch("YOUR_NOTION_API_ENDPOINT");
// Example:
// const response = await fetch(
// "/api/posts/19f9c9aa356180358b65fe657f6ed700"
// );
const data: PageData = await response.json();
setPage(data);
};
fetchData();
}, []);
if (!page) return <div>Loading...</div>;
return (
<div className="max-w-4xl mx-auto p-5 font-sans">
<h1 className="text-3xl font-bold mb-5">{page.title}</h1>
<div>{page.content.map((block) => blockMapper(block))}</div>
</div>
);
}
export default App;- Node.js >= 18.x
- React >= 18.x
- Vite >= 4.x
- Tailwind CSS (optional, for styling)
-
Initialize a Vite + React + TypeScript project:
npm create vite@latest my-notion-app -- --template react-ts cd my-notion-app npm install -
Install Tailwind CSS (if not already installed):
npm install -D tailwindcss postcss autoprefixer npx tailwindcss init -p
Configure
tailwind.config.js:/** @type {import('tailwindcss').Config} */ export default { content: ["./src/**/*.{js,jsx,ts,tsx}"], theme: { extend: {} }, plugins: [], };
Add to
src/index.css:@tailwind base; @tailwind components; @tailwind utilities;
-
Install Notion Mapper:
npm install react-notion-blocks
-
Fetch Notion Data: Integrate with your Notion API backend to retrieve block data.
| Block Type | Description |
|---|---|
| Paragraph | Text paragraphs |
| Heading (1, 2, 3) | Headings of different levels |
| Divider | Horizontal divider |
| Image | Embedded images |
| Code | Code snippets |
| Quote | Blockquotes |
| Bulleted List | Unordered lists |
| Numbered List | Ordered lists |
| To-Do | Checkboxes |
| Table | Tables with rows |
| Callout | Notices with icons |
| Embed | Embedded content (e.g., iframes) |
| Bookmark | Links with previews |
| File/Video/Audio/PDF | Media files |
| Equation | Mathematical expressions |
| Child Page/Database | Nested pages or databases |
| And more... | Full Notion API block support |
To fetch data from a backend (e.g., http://localhost:3001), configure a proxy in vite.config.ts:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import path from "path";
export default defineConfig({
plugins: [react()],
server: {
port: 3000,
proxy: {
"/api": {
target: "http://localhost:3001",
changeOrigin: true,
},
},
},
resolve: {
alias: { "@": path.resolve(__dirname, "./src") },
},
});We welcome contributions! To contribute:
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-feature). - Commit your changes (
git commit -m "Add your feature"). - Push to the branch (
git push origin feature/your-feature). - Open a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Notion API
- React Component Library
- Vite
- TypeScript
- Tailwind CSS
- Notion Blocks Renderer
For issues or suggestions, please open an issue on our GitHub repository.