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
Installation
Open inpnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.jsonnpx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.jsonyarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.jsonbun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useMutationObserver.jsonA 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
| Property | Description | Type | Default |
| -- | ---- |
| target | DOM element or ref | () => Element | Element | MutableRefObject<Element> | - |
| callback | The callback function | (mutations: MutationRecord[], observer: MutationObserver) => void | - |
| options | Setting | MutationObserverInit | - |
Options
For options, please refer to MutationObserver