Skip to content

useMutationObserver ​

A hook that provides the ability to watch for changes being made to the DOM tree, refer to MutationObserver

Examples ​

Default Usage ​

API ​

typescript
useMutationObserver(
  callback: MutationCallback,
  target: Target,
  options?: MutationObserverInit,
);

Params ​

PropertyDescriptionTypeDefault
targetDOM element or ref() => Element | Element | MutableRefObject<Element>-
callbackThe callback function(mutations: MutationRecord[], observer: MutationObserver) => void-
optionsSettingMutationObserverInit-

Options ​

For options, please refer to MutationObserver

Source ​

Source · Document · Demo

Released under the MIT License.