shadcn-ahooks

useMutationObserver

A hook that provides the ability to watch for changes being made to the DOM tree, refer to [MutationObserver](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver)

Overview

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

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.json

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

Examples

Default Usage

API

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

On this page