Skip to content

开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.

feat(text): support update text from outside (#58)

pubuzhixing80e302aa91436
diff --git a/packages/react-text/src/text.tsx b/packages/react-text/src/text.tsx
index da6e1f5..d6c73a6 100644
--- a/packages/react-text/src/text.tsx
+++ b/packages/react-text/src/text.tsx
@@ -1,7 +1,7 @@
import { createEditor, type Descendant, type Element } from 'slate';
import { Editable, RenderLeafProps, Slate, withReact } from 'slate-react';
import type { CustomText, TextProps } from '@plait/common';
-import React, { useMemo, useCallback } from 'react';
+import React, { useMemo, useCallback, useEffect } from 'react';
import { withHistory } from 'slate-history';
import { withText } from './plugins/with-text';
@@ -27,6 +27,13 @@ export const Text: React.FC<TextComponentProps> = (
afterInit && afterInit(editor);
return editor;
}, []);
+ useEffect(() => {
+ if (text === editor.children[0]) {
+ return;
+ }
+ editor.children = [text];
+ editor.onChange();
+ }, [text, editor]);
return (
<Slate
editor={editor}