瀏覽代碼

fix use-behavior bug

David Sehnal 4 年之前
父節點
當前提交
35c778b644
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      src/mol-plugin-ui/hooks/use-behavior.ts

+ 4 - 1
src/mol-plugin-ui/hooks/use-behavior.ts

@@ -19,7 +19,10 @@ export function useBehavior<T>(s: Behavior<T> | undefined): T | undefined {
     const [value, setValue] = useState(s?.value);
 
     useEffect(() => {
-        if (!s) return;
+        if (!s) {
+            if (value !== void 0) setValue(void 0);
+            return;
+        }
         let fst = true;
         const sub = s.subscribe((v) => {
             if (fst) {