UNPKG

634 BTypeScriptView Raw
1/**
2 * Observe mutations on a DOM node or tree of DOM nodes.
3 * Depends on the `MutationObserver` api.
4 *
5 * ```ts
6 * const [element, attachRef] = useCallbackRef(null);
7 *
8 * useMutationObserver(element, { subtree: true }, (records) => {
9 *
10 * });
11 *
12 * return (
13 * <div ref={attachRef} />
14 * )
15 * ```
16 *
17 * @param element The DOM element to observe
18 * @param config The observer configuration
19 * @param callback A callback fired when a mutation occurs
20 */
21declare function useMutationObserver(element: Element | null | undefined, config: MutationObserverInit, callback: MutationCallback): void;
22export default useMutationObserver;