How splitbee/react-notion works
This project is a React-based library that renders Notion pages into a web-friendly format. It is designed as a lightweight renderer and is best used to display content from Notion as a blog, documentation site, or personal page. The main goal of this project is to transform the Notion API’s response (the block map of a Notion page) into React elements with support for rich content (text, headings, images, code blocks with PrismJS highlighting, etc).
Main Components and Their Roles
• Library Core (src/index.tsx and src/renderer.tsx): This is the entry point that initializes the NotionRenderer and handles the mapping of Notion blocks to React components.
• Block Rendering Modules (src/block.tsx): Responsible for interpreting and rendering individual Notion blocks.
• React Components (src/components/):
• asset.tsx – Likely handles media (images, other assets).
• code.tsx – Renders code blocks with PrismJS integration.
• Utilities & Types (src/utils.ts and src/types.ts): Provide helper functions, type definitions, and other support routines used across the library.
• Styles (src/styles.css): The main stylesheet that dictates the appearance of the rendered Notion pages.
• Example Application (example folder): Contains a minimal Next.js (or React) example that demonstrates how to integrate and use the library. This includes configuration for TypeScript, environment definitions, and example page components.
Interactions and Data Flow
• Input: The library expects a Notion API response in the form of a block map (a collection of blocks with their content and metadata).
• Flow: The main NotionRenderer receives the block map and iterates over it. Depending on the block type (e.g., text, heading, image, code), it delegates rendering to specific component modules.
• External Integration: Although the library does not handle API communication directly, the README explains that an external service (like the notion-api-worker) is used to fetch data. You might indicate an “External Notion API” component that feeds data into a client (shown in the example) which then passes it to NotionRenderer.
Architectural Patterns and Design Principles
• Component-Based Architecture: Emphasize the React component hierarchy where each block type is modular and can be extended or replaced.
• Separation of Concerns: The library cleanly separates rendering logic (in src/renderer.tsx and block.tsx) from UI components (in src/components) and styles (in src/styles.css).
• Reusability and Extensibility: The organization into modules (utilities, types, components) allows for easy extension and maintenance.