diff --git a/packages/client/src/components/document/editor/editor.tsx b/packages/client/src/components/document/editor/editor.tsx index a709124..1ba184a 100644 --- a/packages/client/src/components/document/editor/editor.tsx +++ b/packages/client/src/components/document/editor/editor.tsx @@ -65,6 +65,9 @@ export const Editor: React.FC = ({ user: currentUser, documentId, author onSynced() { toggleLoading(false); }, + onStatus({ status }) { + setStatus(status); + }, }, }); }, [documentId, currentUser, toggleLoading]); @@ -85,22 +88,15 @@ export const Editor: React.FC = ({ user: currentUser, documentId, author // } }, 50), + onDestroy() { + destoryProvider(provider, 'EDITOR'); + }, }, [authority, provider] ); const [mentionUsersSettingVisible, toggleMentionUsersSettingVisible] = useToggle(false); const [mentionUsers, setMentionUsers] = useState([]); - useEffect(() => { - provider.on('status', async ({ status }) => { - setStatus(status); - }); - - return () => { - destoryProvider(provider, 'EDITOR'); - }; - }, [documentId, provider, authority]); - useEffect(() => { if (!authority || !authority.editable) return; diff --git a/packages/client/src/components/document/reader/editor.tsx b/packages/client/src/components/document/reader/editor.tsx index 10b5009..ad01c84 100644 --- a/packages/client/src/components/document/reader/editor.tsx +++ b/packages/client/src/components/document/reader/editor.tsx @@ -64,13 +64,10 @@ export const Editor: React.FC = ({ user, documentId, document, children // @ts-ignore taskItemClickable: true, }, - }); - - useEffect(() => { - return () => { + onDestroy() { destoryProvider(provider, 'READER'); - }; - }, [provider]); + }, + }); return (