跳转到内容

useMutationObserver ​

一个监听指定的 DOM 树发生变化的 Hook,参考 MutationObserver

代码演示 ​

基础用法 ​

API ​

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

Params ​

参数说明类型默认值
callback触发的回调函数(mutations: MutationRecord[], observer: MutationObserver) => void-
targetDOM 节点或者 RefElement | () => Element | MutableRefObject<Element>-
options设置项MutationObserverInit{}

Options ​

配置项请参考 MutationObserver

Source ​

源码 · 文档 · 示例

基于 MIT 许可发布