Browse Source

fix: multiple sockets callback bind after switching db back and (#774)

* fix: multiple sockets callback bind after swithcing db back and
forcth

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

* remove console

Signed-off-by: ryjiang <jiangruiyi@gmail.com>

---------

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 4 months ago
parent
commit
12bb8f89a8
1 changed files with 2 additions and 3 deletions
  1. 2 3
      client/src/context/Data.tsx

+ 2 - 3
client/src/context/Data.tsx

@@ -450,7 +450,7 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
       // clear data
       // clear data
       setCollections([]);
       setCollections([]);
       // remove all listeners
       // remove all listeners
-      socket.current?.offAny();
+      socket.current?.off(WS_EVENTS.COLLECTION_UPDATE, updateCollections);
       // listen to backend collection event
       // listen to backend collection event
       socket.current?.on(WS_EVENTS.COLLECTION_UPDATE, updateCollections);
       socket.current?.on(WS_EVENTS.COLLECTION_UPDATE, updateCollections);
 
 
@@ -459,8 +459,7 @@ export const DataProvider = (props: { children: React.ReactNode }) => {
     }
     }
 
 
     return () => {
     return () => {
-      // remove all listeners when component unmount
-      socket.current?.offAny();
+      socket.current?.off(WS_EVENTS.COLLECTION_UPDATE, updateCollections);
     };
     };
   }, [updateCollections, connected]);
   }, [updateCollections, connected]);