More Premium Hugo Themes Premium React Themes

Notion Blocks Chakra UI

Parse Notion blocks from official API to Chakra UI components

Notion Blocks Chakra UI

Parse Notion blocks from official API to Chakra UI components

Author Avatar Theme by baptistearno
Github Stars Github Stars: 5
Last Commit Last Commit: Sep 7, 2021 -
First Commit Created: Dec 18, 2023 -
Notion Blocks Chakra UI screenshot

Overview:

This article discusses the process of parsing Notion blocks into Chakra UI React components. It also provides instructions for getting started and using the custom image component. The author mentions that the inspiration for this library came from samuelkraft/notion-blog-nextjs and shares their portfolio source code that utilizes this library.

Features:

  • Parse Notion blocks into Chakra UI React components
  • Custom image component
  • Support for text, headings, lists, and other Notion block types
  • Easy integration with existing React projects
  • Inspiration from samuelkraft/notion-blog-nextjs

Installation:

To install and use this library, follow these steps:

  1. Clone the repository into your local machine:

    git clone <repository-url>
    
  2. Install the required dependencies:

    npm install
    
  3. Import the library in your React project:

    import { NotionParser, CustomImage } from 'notion-parser';
    
  4. Create a new instance of the NotionParser class:

    const parser = new NotionParser();
    
  5. Parse the Notion blocks into Chakra UI React components:

    const parsedBlocks = parser.parseBlocks(notionBlocks);
    
  6. Use the parsed blocks in your React components:

    {parsedBlocks.map((block, index) => (
     <React.Fragment key={index}>
      {block.type === 'text' && <Text>{block.value}</Text>}
      {block.type === 'heading' && <Heading>{block.value}</Heading>}
      {block.type === 'list' && <List>{block.value}</List>}
      // ...add more cases for other block types
     </React.Fragment>
    ))}
    
  7. For custom images, use the CustomImage component and pass the image URL:

    <CustomImage src={imageUrl} alt="Image description" />
    

Summary:

This article demonstrates how to parse Notion blocks into Chakra UI React components and provides a custom image component for handling images in Notion. The installation guide walks through the required steps and code snippets for setting up and using the library. By following the instructions, users can easily integrate Notion blocks into their React projects and utilize the custom image component for handling images unsupported by the Notion API.