Skip to content

Commit

Permalink
chore: use c-component/util
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Jan 21, 2025
1 parent e0403d2 commit e24cfca
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ coverage
yarn.lock
/es/
package-lock.json
pnpm-lock.yaml
.doc

# dumi
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rc-component/mutate-observer",
"version": "1.1.0",
"version": "2.0.0",
"description": "React MutateObserver Component",
"keywords": [
"react",
Expand Down Expand Up @@ -43,18 +43,19 @@
},
"dependencies": {
"@babel/runtime": "^7.18.0",
"classnames": "^2.3.2",
"rc-util": "^5.24.4"
"@rc-component/util": "^1.2.0",
"classnames": "^2.3.2"
},
"devDependencies": {
"@rc-component/father-plugin": "^1.0.0",
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.0.0",
"@types/jest": "^26.0.20",
"@types/node": "^20.9.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/node": "^22.10.7",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.3",
"@umijs/fabric": "^3.0.0",
"cheerio": "1.0.0-rc.12",
"dumi": "^2.0.0",
"eslint": "^8.54.0",
"eslint-plugin-jest": "^27.6.0",
Expand All @@ -67,7 +68,6 @@
"react": "^18.0.0",
"react-dom": "^18.0.0",
"typescript": "^5.0.0",
"cheerio": "1.0.0-rc.12",
"umi-test": "^1.9.7"
},
"peerDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions src/MutateObserver.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
import { supportRef, useComposeRef } from 'rc-util/lib/ref';
import findDOMNode from 'rc-util/lib/Dom/findDOMNode';
import useEvent from 'rc-util/lib/hooks/useEvent';
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
import { supportRef, useComposeRef } from '@rc-component/util/lib/ref';
import findDOMNode from '@rc-component/util/lib/Dom/findDOMNode';
import useEvent from '@rc-component/util/lib/hooks/useEvent';
import DomWrapper from './wrapper';
import type { MutationObserverProps } from './interface';
import useMutateObserver from './useMutateObserver';
Expand Down Expand Up @@ -46,7 +46,7 @@ const MutateObserver: React.FC<MutationObserverProps> = props => {
return (
<DomWrapper ref={wrapperRef}>
{canRef
? React.cloneElement(children as any, { ref: mergedRef })
? React.cloneElement<any>(children, { ref: mergedRef })
: children}
</DomWrapper>
);
Expand Down
12 changes: 7 additions & 5 deletions src/useMutateObserver.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import canUseDom from 'rc-util/lib/Dom/canUseDom';
import * as React from 'react';
import canUseDom from '@rc-component/util/lib/Dom/canUseDom';
import React from 'react';

const defaultOptions: MutationObserverInit = {
subtree: true,
childList: true,
attributeFilter: ['style', 'class'],
};

export default function useMutateObserver(
const useMutateObserver = (
nodeOrList: HTMLElement | HTMLElement[],
callback: MutationCallback,
options: MutationObserverInit = defaultOptions,
) {
) => {
React.useEffect(() => {
if (!canUseDom() || !nodeOrList) {
return;
Expand All @@ -33,4 +33,6 @@ export default function useMutateObserver(
instance?.disconnect();
};
}, [options, nodeOrList]);
}
};

export default useMutateObserver;
6 changes: 1 addition & 5 deletions src/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React from 'react';

interface DomWrapperProps {
children: React.ReactNode;
}

class DomWrapper extends React.Component<DomWrapperProps> {
class DomWrapper extends React.Component<React.PropsWithChildren> {
render() {
return this.props.children;
}
Expand Down

0 comments on commit e24cfca

Please sign in to comment.