Navigation menu in Preferences (#2304)

This commit is contained in:
Alex Andreev authored and GitHub committed 2021-03-15 08:57:19 -04:00
1 parent 8e1583a59c
commit 5c373a886c
20 files changed
+838 -254

No files matched your search

+1
View File
@@ -3,3 +3,4 @@
export * from "./useStorage";
export * from "./useOnUnmount";
export * from "./useInterval";
export * from "./useMutationObserver";
+27
View File
@@ -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]);
}