UNPKG

1.18 kBTypeScriptView Raw
1/**
2 * Observe mutations on a DOM node or tree of DOM nodes.
3 * Depends on the `MutationObserver` api.
4 *
5 * ```tsx
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;
22/**
23 * Observe mutations on a DOM node or tree of DOM nodes.
24 * use a `MutationObserver` and return records as the are received.
25 *
26 * ```tsx
27 * const [element, attachRef] = useCallbackRef(null);
28 *
29 * const records = useMutationObserver(element, { subtree: true });
30 *
31 * return (
32 * <div ref={attachRef} />
33 * )
34 * ```
35 *
36 * @param element The DOM element to observe
37 * @param config The observer configuration
38 */
39declare function useMutationObserver(element: Element | null | undefined, config: MutationObserverInit): MutationRecord[];
40export default useMutationObserver;