https://github.com/react-component/mutate-observer
https://github.com/react-component/mutate-observer
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/react-component/mutate-observer
- Owner: react-component
- License: mit
- Created: 2022-12-08T14:29:36.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2025-01-24T10:35:27.000Z (11 months ago)
- Last Synced: 2025-08-26T11:20:50.827Z (4 months ago)
- Language: TypeScript
- Size: 38.1 KB
- Stars: 8
- Watchers: 4
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rc-mutate-observer
MutateObserver for React.
[![NPM version][npm-image]][npm-url] [](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![npm download][download-image]][download-url]
[npm-image]: http://img.shields.io/npm/v/@rc-component/mutate-observer.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/@rc-component/mutate-observer
[github-actions-image]: https://github.com/react-component/mutate-observer/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/mutate-observer/actions
[codecov-image]: https://img.shields.io/codecov/c/github/@rc-component/mutate-observer/master.svg?style=flat-square
[download-image]: https://img.shields.io/npm/dm/@rc-component/mutate-observer.svg?style=flat-square
[download-url]: https://www.npmjs.com/package/@rc-component/mutate-observer
## Development
```bash
npm install
npm run start
open http://localhost:8000
```
## Install
[](https://www.npmjs.com/package/@rc-component/mutate-observer)
## Usage
```tsx | pure
import React from 'react';
import MutateObserver from './src';
const onMutate = (mutations: MutationRecord[], observer: MutationObserver) => {
console.log(mutation);
console.log(observer);
};
const Demo: React.FC = () => {
return (
test
);
};
export default Demo;
```
## 🔥 API
We use typescript to create the Type definition. You can view directly in IDE. But you can still check the type definition [here](https://github.com/react-component/mutate-observer/blob/master/src/interface.ts).
### mutate-observer
| Prop | Description | Type | Default |
| -------- | ---------------------------------------------------------------------------------------------------------------- | -------------------- | ------- |
| onMutate | A function which will be called on each DOM change that qualifies given the observed node or subtree and options | MutationCallback | - |
| options | An object providing options that describe which DOM mutations should be reported to mutationObserver's callback | MutationObserverInit | - |