Get started - Get started with Liveblocks, BlockNote, and React

Liveblocks is a realtime collaboration infrastructure for building performant collaborative experiences. Follow the following steps to start adding collaboration to your React application using the APIs from the @liveblocks/react-blocknote package.

Quickstart

  1. Install Liveblocks and BlockNote

    Every Liveblocks package should use the same version.

    $npm install @liveblocks/client @liveblocks/react @liveblocks/react-ui @liveblocks/react-blocknote @blocknote/core @blocknote/react @blocknote/mantine
  2. Initialize the liveblocks.config.ts file

    We can use this file later to define types for our application.

    $npx create-liveblocks-app@latest --init --framework react
  3. Set up the Liveblocks client

    Liveblocks uses the concept of rooms, separate virtual spaces where people collaborate, and to create a realtime experience, multiple users must be connected to the same room. Set up a Liveblocks client with LiveblocksProvider, and join a room with RoomProvider.

    App.tsx
    "use client";
    import { LiveblocksProvider, RoomProvider,} from "@liveblocks/react/suspense";import { Editor } from "./Editor";
    export default function App() { return ( <LiveblocksProvider publicApiKey={""}> <RoomProvider id="my-room"> {/* ... */} </RoomProvider> </LiveblocksProvider> );}
  4. Join a Liveblocks room

    After setting up the room, you can add collaborative components inside it, using ClientSideSuspense to add loading spinners to your app.

    App.tsx
    "use client";
    import { LiveblocksProvider, RoomProvider, ClientSideSuspense,} from "@liveblocks/react/suspense";import { Editor } from "./Editor";
    export default function App() { return ( <LiveblocksProvider publicApiKey={""}> <RoomProvider id="my-room"> <ClientSideSuspense fallback={<div>Loading…</div>}> <Editor /> </ClientSideSuspense> </RoomProvider> </LiveblocksProvider> );}
  5. Set up the collaborative BlockNote text editor

    Now that we set up Liveblocks, we can start integrating BlockNote and Liveblocks in the Editor.tsx file. To make the editor collaborative, we can add useCreateBlockNoteWithLiveblocks from @liveblocks/react-blocknote.

    Editor.tsx
    "use client";
    import { useCreateBlockNoteWithLiveblocks } from "@liveblocks/react-blocknote";import { BlockNoteView } from "@blocknote/mantine";import { Threads } from "./Threads";
    export function Editor() { const editor = useCreateBlockNoteWithLiveblocks({});
    return ( <div> <BlockNoteView editor={editor} className="editor" /> <Threads editor={editor} /> </div> );}
  6. Render threads and composer

    To add Comments to your text editor, we need to import a thread composer and list each thread on the page. Create a Threads.tsx file that uses FloatingComposer for creating new threads, alongside AnchoredThreads and FloatingThreads for displaying threads on desktop and mobile.

    Threads.tsx
    import { useThreads } from "@liveblocks/react/suspense";import {  AnchoredThreads,  FloatingComposer,  FloatingThreads,} from "@liveblocks/react-blocknote";import { BlockNoteEditor } from "@blocknote/core";
    export function Threads({ editor }: { editor: BlockNoteEditor | null }) { const { threads } = useThreads({ query: { resolved: false } });
    if (!editor) { return null; }
    return ( <> <div className="anchored-threads"> <AnchoredThreads editor={editor} threads={threads} /> </div> <FloatingThreads editor={editor} threads={threads} className="floating-threads" /> <FloatingComposer editor={editor} className="floating-composer" /> </> );}
  7. Style your editor

    We can create some custom styles to position the editor and threads—import globals.css, alongside the default Liveblocks styles. You can import them into the root layout of your app or directly into a CSS file with @import.

    app/layout.tsx
    import "@blocknote/core/fonts/inter.css";import "@blocknote/mantine/style.css";import "@liveblocks/react-ui/styles.css";import "@liveblocks/react-ui/styles/dark/media-query.css";import "@liveblocks/react-tiptap/styles.css";import "./globals.css";
  8. Next: authenticate and add your users

    Text Editor is set up and working now, but each user is anonymous—the next step is to authenticate each user as they connect, and attach their name, color, and avatar, to their cursors and mentions.

    Add your users to Text Editor

  9. Optional: add more features

    BlockNote is easy to extend, and a number of extensions are already available, making it possible to quickly create complex rich-text applications. Any additional features you add will be supported using Liveblocks.

    Read the BlockNote docs

What to read next

Congratulations! You now have set up the foundation for your collaborative BlockNote text editor inside your React application.


Examples using BlockNote

We use cookies to collect data to improve your experience on our site. Read our Privacy Policy to learn more.