From 5540c0dfab97c9881ceb7f4e817b989cca5da4da Mon Sep 17 00:00:00 2001 From: fantasticit Date: Mon, 2 May 2022 17:29:22 +0800 Subject: [PATCH] fix: fix the moment to delete provider --- .../src/components/document/editor/editor.tsx | 16 ++++++---------- .../src/components/document/reader/editor.tsx | 9 +++------ 2 files changed, 9 insertions(+), 16 deletions(-) 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 (