snapshot of https://github.com/shadcn-ui/ui.git (main, 2026-09-15; blobs > 131072B omitted)
This commit is contained in:
20
apps/v4/hooks/use-mutation-observer.ts
Normal file
20
apps/v4/hooks/use-mutation-observer.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import * as React from "react"
|
||||
|
||||
export const useMutationObserver = (
|
||||
ref: React.RefObject<HTMLElement | null>,
|
||||
callback: MutationCallback,
|
||||
options: MutationObserverInit = {
|
||||
attributes: true,
|
||||
characterData: true,
|
||||
childList: true,
|
||||
subtree: true,
|
||||
}
|
||||
) => {
|
||||
React.useEffect(() => {
|
||||
if (ref.current) {
|
||||
const observer = new MutationObserver(callback)
|
||||
observer.observe(ref.current, options)
|
||||
return () => observer.disconnect()
|
||||
}
|
||||
}, [ref, callback, options])
|
||||
}
|
||||
Reference in New Issue
Block a user