Skip to content

Commit a3b11b6

Browse files
committed
WiP: Add MutationObserver to <finder-file-select>
1 parent d8bf204 commit a3b11b6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

client/browser/FinderFileSelect.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {useEffect, useRef, useState} from 'react';
22
import FileSelectDialog from './FileSelectDialog';
3+
import {useMutationObserver} from '../common/MutationObserver';
34

45

56
export default function FinderFileSelect(props) {

client/common/MutationObserver.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {useEffect, RefObject} from 'react';
2+
3+
4+
export function useMutationObserver(ref: RefObject<Element>, callback: MutationCallback, options: MutationObserverInit) {
5+
useEffect(() => {
6+
if (ref.current) {
7+
const observer = new MutationObserver(callback);
8+
observer.observe(ref.current, options);
9+
return () => observer.disconnect();
10+
}
11+
}, [ref]);
12+
}

0 commit comments

Comments
 (0)