mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Navigation menu in Preferences (#2304)
This commit is contained in:
1 parent
8e1583a59c
commit
5c373a886c
20 files changed
+838
-254
No files matched your search
@@ -3,3 +3,4 @@
|
||||
export * from "./useStorage";
|
||||
export * from "./useOnUnmount";
|
||||
export * from "./useInterval";
|
||||
export * from "./useMutationObserver";
|
||||
@@ -0,0 +1,27 @@
|
||||
import { useEffect } from "react";
|
||||
|
||||
const config: MutationObserverInit = {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
attributes: false,
|
||||
characterData: false
|
||||
};
|
||||
|
||||
export function useMutationObserver(
|
||||
root: Element,
|
||||
callback: MutationCallback,
|
||||
options: MutationObserverInit = config
|
||||
) {
|
||||
|
||||
useEffect(() => {
|
||||
if (root) {
|
||||
const observer = new MutationObserver(callback);
|
||||
|
||||
observer.observe(root, options);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
};
|
||||
}
|
||||
}, [callback, options]);
|
||||
}
|
||||
Reference in new issue
Block a user