Examples
Collaboration
Collaborative Editing with LiveBlocks

Collaborative Editing with LiveBlocks

In this example, we use LiveBlocks to let multiple users collaborate on a single BlockNote document in real-time.

Try it out: Open this page ion a new browser tab or window to see it in action!

Relevant Docs:

import { BlockNoteView, useCreateBlockNote } from "@blocknote/react";
import "@blocknote/react/style.css";
import { createClient } from "@liveblocks/client";
import LiveblocksProvider from "@liveblocks/yjs";
import * as Y from "yjs";
 
// Sets up Liveblocks client.
const client = createClient({
  publicApiKey:
    "pk_dev_lJAS4XHx3l1e0x_Gh9VMtrvo8PEB1vrNarC2YRtAOp4t6i9_QAcSX2U953GS6v7B",
});
// Enters a multiplayer room.
// Use a unique name as a "room" for your application.
const { room } = client.enterRoom("your-project-name", {
  initialPresence: {},
});
 
// Sets up Yjs document and LiveBlocks Yjs provider.
const doc = new Y.Doc();
const provider = new LiveblocksProvider(room, doc);
 
export default function App() {
  const editor = useCreateBlockNote({
    collaboration: {
      // The Yjs Provider responsible for transporting updates:
      provider,
      // Where to store BlockNote data in the Y.Doc:
      fragment: doc.getXmlFragment("document-store"),
      // Information (name and color) for this user:
      user: {
        name: "My Username",
        color: "#ff0000",
      },
    },
  });
 
  // Renders the editor instance.
  return <BlockNoteView editor={editor} />;
}