Browse Source

fix use-behavior bug

David Sehnal 4 years ago
parent
commit
35c778b644
1 changed files with 4 additions and 1 deletions
  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) {