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-lexical
package.
Every Liveblocks package should use the same version.
liveblocks.config.ts
fileWe can use this file later to define types for our application.
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
.
After setting up the room, you can add collaborative components inside it, using
ClientSideSuspense
to add loading spinners to your app.
Now that we set up Liveblocks, we can start integrating Lexical and Liveblocks in the Editor.tsx
file.
To make the editor collaborative, we can use
LiveblocksPlugin
from @liveblocks/lexical-react
. FloatingComposer
is optional and adds Comments to your text editor.
To create annotations and post comments, we need to create a button for triggers the action.
Create a toolbar in Toolbar.tsx
that enables this.
When each thread and comment is created, we need to render it to the page. Create
a Threads.tsx
file that lists each thread.
Lexical text editor is unstyled by default, so we can create some custom styles for it in a globals.css
file. 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
.
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
Lexical is a highly extensible text editor and it's possible to create complex rich-text applications. A great example is in the Lexical playground which enables features such as tables, text highlights, embedded images, and more. This is all supported using Liveblocks.
Learn more about Lexical
Congratulations! You now have set up the foundation for your collaborative Lexical text editor inside your React application.
@liveblocks/lexical-react
API Reference@liveblocks/node-lexical
API Reference