File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
packages/lexical-website/docs/collaboration Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ $ HOST=localhost PORT=1234 YPERSISTENCE=./yjs-wss-db npx y-websocket
4040** Get basic collaborative Lexical setup:**
4141
4242``` tsx
43+ import { useCallback } from ' react' ;
44+
4345import {$getRoot , $createParagraphNode , $createTextNode } from ' lexical' ;
4446import {LexicalCollaboration } from ' @lexical/react/LexicalCollaborationContext' ;
4547import {LexicalComposer } from ' @lexical/react/LexicalComposer' ;
@@ -65,6 +67,19 @@ function Editor() {
6567 theme: {},
6668 };
6769
70+ const getDocFromMap = (id : string , yjsDocMap : Map <string , Y .Doc >): Y .Doc => {
71+ let doc = yjsDocMap .get (id );
72+
73+ if (doc === undefined ) {
74+ doc = new Y .Doc ();
75+ yjsDocMap .set (id , doc );
76+ } else {
77+ doc .load ();
78+ }
79+
80+ return doc ;
81+ }
82+
6883 const providerFactory = useCallback (
6984 (id : string , yjsDocMap : Map <string , Y .Doc >) => {
7085 const doc = getDocFromMap (id , yjsDocMap );
@@ -88,7 +103,7 @@ function Editor() {
88103 providerFactory = { providerFactory }
89104 />
90105 </LexicalComposer >
91- <LexicalCollaboration >
106+ </ LexicalCollaboration >
92107 );
93108}
94109```
You can’t perform that action at this time.
0 commit comments