New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@bettaibi/react-blocknote

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bettaibi/react-blocknote

A modern, versatile rich text editor component for React applications with an elegant UI and Notion-like functionality. Supports both React 18 and React 19.

latest
Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
31
Maintainers
1
Weekly downloads
 
Created
Source

React BlockNote

A modern, versatile rich text editor component for React applications with an elegant UI and Notion-like functionality.

GitHub stars

⭐ If you find this project useful or interesting, please consider giving it a star on GitHub! Your support helps us grow and improve the library for everyone.

Features

  • 🎨 Elegant & modern UI with floating toolbar and bubble menu
  • 📊 Full table support with intuitive table controls
  • 🔗 Links and image embedding
  • ✅ Task lists and checklists
  • 📝 Code blocks with syntax highlighting
  • 🔤 Rich text formatting (bold, italic, underline, etc.)
  • 📑 Comprehensive heading options (H1-H6) with dropdown menu
  • 🧮 Math formula support (KaTeX)
  • 📱 Fully responsive design that works on all devices
  • 🎯 Clean, accessible component API
  • 🔌 Markdown import/export capabilities

Installation

npm install @bettaibi/react-blocknote

Peer Dependencies

React BlockNote has a few peer dependencies that need to be installed:

npm install @radix-ui/react-dropdown-menu@2.1.12 @radix-ui/react-popover@1.1.11 katex@0.16.22

This approach minimizes the number of peer dependencies while maintaining an optimal package size.

React Version Compatibility

React BlockNote supports both React 18 and React 19. The package is designed to work seamlessly with either version without any breaking changes.

  • React 18: Full support with all features
  • React 19: Full support with all features, including the latest React improvements and concurrent features

Note: For React 19 users, the package has been specifically tested and optimized to work with Next.js 15 and other React 19 applications. All React-specific imports and type references have been updated for maximum compatibility.

Bundle Size Optimization

For detailed information on how to optimize the bundle size and performance of React BlockNote in your application, please refer to our Optimization Guide.

Usage

Regular BlockNote Component

For most use cases, you can use the pre-built BlockNote component:

import { BlockNote, BlockNoteProvider } from "@bettaibi/react-blocknote";
import "@bettaibi/react-blocknote/styles.css"; // Import styles

function MyEditor() {
  const [content, setContent] = useState("");

  return (
    // if you are using tailwind ensure adding prose classNames to the BlockNote wrapper
    <div className="lg:prose-md prose h-full max-w-full">
      <BlockNoteProvider
        value={content}
        onChange={setContent}
        placeholder="Start typing..."
        outputFormat="html" // or "markdown"
      >
        <BlockNote />
      </BlockNoteProvider>
    </div>
  );
}

Custom BlockNote with Atomic Components

For highly customized editors, you have two options for building your own editor:

Option 1: Using Atomic Components

Use pre-built atomic components with built-in functionality:

import {
  BlockNoteProvider,
  BlockNoteContent,
  BoldButton,
  ItalicButton,
  UnderlineButton,
} from "@bettaibi/react-blocknote/atomic";
import "@bettaibi/react-blocknote/styles.css";

function CustomEditor() {
  const [content, setContent] = useState("");

  return (
    <BlockNoteProvider value={content} onChange={setContent}>
      <div className="custom-editor">
        {/* Custom toolbar with atomic components */}
        <div className="toolbar">
          <BoldButton iconSize={18} />
          <ItalicButton iconSize={18} />
          <UnderlineButton iconSize={18} />
        </div>

        {/* Editor content */}
        <BlockNoteContent />
      </div>
    </BlockNoteProvider>
  );
}

Option 2: Using Custom Hooks

Use hooks to build completely custom UI components:

import {
  BlockNoteProvider,
  BlockNoteContent,
  useBlockNoteHandlers,
  useBlockNoteValues,
} from "@bettaibi/react-blocknote/atomic";
import "@bettaibi/react-blocknote/styles.css";

function CustomEditor() {
  const [content, setContent] = useState("");
  const { handleBold, handleItalic, handleUnderline } = useBlockNoteHandlers();
  const { canBold, canItalic, canUnderline } = useBlockNoteValues();

  return (
    <BlockNoteProvider value={content} onChange={setContent}>
      <div className="custom-editor">
        {/* Custom toolbar with custom buttons */}
        <div className="toolbar">
          <button className="btn" disabled={!canBold} onClick={handleBold}>
            Bold
          </button>
          <button className="btn" disabled={!canItalic} onClick={handleItalic}>
            Italic
          </button>
          <button
            className="btn"
            disabled={!canUnderline}
            onClick={handleUnderline}
          >
            Underline
          </button>
        </div>

        {/* Editor content */}
        <BlockNoteContent />
      </div>
    </BlockNoteProvider>
  );
}

Server-Side Rendering

When using SSR frameworks like Next.js, dynamically import the editor component on client-side only. This prevents Next.js from trying to use the DOMParser API during server-side rendering, which was causing the "DOMParser is not defined" error

import dynamic from "next/dynamic";

const BlockNote = dynamic(
  () => import("@bettaibi/react-blocknote").then((mod) => mod.BlockNote),
  { ssr: false }
);

Props

BlockNote Component Props

PropTypeDefaultDescription
classNamestring''Additional CSS class for the editor container
showToolbarbooleantrueWhether to show the toolbar
showBubbleMenubooleantrueWhether to show the bubble menu on text selection

BlockNoteProvider Props

PropTypeDefaultDescription
childrenReact.ReactNode-React children to be wrapped by the provider
valuestring''The editor content as HTML or Markdown
onChangefunction-Callback fired when content changes. Receives the new content as argument
placeholderstring'Start typing or paste a markdown file...'Placeholder text when editor is empty
readOnlybooleanfalseWhether the editor is in read-only mode
outputFormat'html' | 'markdown''html'The format of the output in the onChange callback

Atomic Component Props

All atomic components accept standard button props plus:

PropTypeDefaultDescription
classNamestring''Additional CSS class for the button
iconSizenumber16Size of the icon in pixels
childrenReact.ReactNode-Custom content to replace the default icon

Features

Text Formatting

The editor supports a wide range of text formatting options:

  • Bold, italic, underline
  • Headings (H1-H6) via convenient dropdown menu
  • Lists (ordered, unordered, task lists)
  • Text alignment (left, center, right)
  • Code blocks with syntax highlighting
  • Subscript and superscript
  • Math formulas using KaTeX
  • Contextual bubble menu that appears on text selection
  • Accessible popover components for links and images

Tables

Create and manage tables with an intuitive dropdown menu:

  • Insert tables
  • Add/delete rows and columns
  • Format table cells

Easily add links and images with a clean, accessible UI.

Atomic Components

When importing from @bettaibi/react-blocknote/atomic, you have access to all these atomic components:

Text Formatting Components

ComponentDescription
BoldButtonToggle bold text formatting
ItalicButtonToggle italic text formatting
UnderlineButtonToggle underline text formatting
StrikeButtonToggle strikethrough text formatting
CodeButtonToggle inline code formatting

Heading Components

ComponentDescription
H1ButtonSet heading level 1
H2ButtonSet heading level 2
H3ButtonSet heading level 3
H4ButtonSet heading level 4
H5ButtonSet heading level 5
H6ButtonSet heading level 6
NormalTextButtonConvert to normal paragraph text

List Components

ComponentDescription
BulletListButtonToggle bullet list
OrderedListButtonToggle ordered list
TaskListButtonToggle task list

Block Components

ComponentDescription
CodeBlockButtonToggle code block
BlockquoteButtonToggle blockquote

Alignment Components

ComponentDescription
AlignLeftButtonAlign text to left
AlignCenterButtonAlign text to center
AlignRightButtonAlign text to right

History Components

ComponentDescription
UndoButtonUndo last action
RedoButtonRedo last action

Core Components

ComponentDescription
BlockNoteContentThe main editor content area
BubbleMenuContextual menu that appears on text selection

Hooks

useBlockNoteHandlers()

Returns handlers for all editor operations:

CategoryHandlerDescription
Text FormattinghandleBoldToggle bold formatting
handleItalicToggle italic formatting
handleUnderlineToggle underline formatting
handleStrikeToggle strikethrough formatting
handleCodeToggle inline code formatting
HeadingshandleHeading1Set heading level 1
handleHeading2Set heading level 2
handleHeading3Set heading level 3
handleHeading4Set heading level 4
handleHeading5Set heading level 5
handleHeading6Set heading level 6
handleNormalTextConvert to normal paragraph
ListshandleBulletListToggle bullet list
handleOrderedListToggle ordered list
handleTaskListToggle task list
BlockshandleCodeBlockToggle code block
handleBlockquoteToggle blockquote
AlignmenthandleAlignLeftAlign text to left
handleAlignCenterAlign text to center
handleAlignRightAlign text to right
HistoryhandleUndoUndo last action
handleRedoRedo last action
MediahandleImageInsert image
handleLinkInsert/edit link
TableshandleInsertTableInsert new table
handleDeleteTableDelete current table
handleAddColumnBeforeAdd column before current
handleAddColumnAfterAdd column after current
handleDeleteColumnDelete current column
handleAddRowBeforeAdd row before current
handleAddRowAfterAdd row after current
handleDeleteRowDelete current row

useBlockNoteValues()

Returns state values for UI control:

CategoryValueDescription
Active State CheckersgetActiveMarkCheck if a mark/node is active
getTextAlignStateCheck if specific text alignment is active
TextAlignText alignment constants
HistorycanUndoCheck if undo is available
canRedoCheck if redo is available
Text FormattingcanBoldCheck if bold can be applied
canItalicCheck if italic can be applied
canUnderlineCheck if underline can be applied
canStrikeCheck if strikethrough can be applied
canCodeCheck if inline code can be applied
HeadingscanHeading1Check if heading 1 can be applied
canHeading2Check if heading 2 can be applied
canHeading3Check if heading 3 can be applied
canHeading4Check if heading 4 can be applied
canHeading5Check if heading 5 can be applied
canHeading6Check if heading 6 can be applied
canNormalTextCheck if normal text can be applied
ListscanBulletListCheck if bullet list can be applied
canOrderedListCheck if ordered list can be applied
canTaskListCheck if task list can be applied
BlockscanCodeBlockCheck if code block can be applied
canBlockquoteCheck if blockquote can be applied
TablescanInsertTableCheck if table can be inserted
canDeleteTableCheck if table can be deleted
canAddColumnBeforeCheck if column can be added before
canAddColumnAfterCheck if column can be added after
canDeleteColumnCheck if column can be deleted
canAddRowBeforeCheck if row can be added before
canAddRowAfterCheck if row can be added after
canDeleteRowCheck if row can be deleted

Hook Usage Examples

// Check if bold is currently active
const isBoldActive = getActiveMark(BlockNoteMark.BOLD);

// Check if text is center-aligned
const isCenterAligned = getTextAlignState(TextAlign.CENTER);

// Check if undo operation is available
const canUndoOperation = canUndo;

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Requirements

  • React 18.0.0 or higher (supports both React 18 and 19)
  • Node.js 18.0.0 or higher

Credits

This package is built on top of several amazing open-source projects:

Keywords

react

FAQs

Package last updated on 27 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts