diff --git a/.gitignore b/.gitignore index 21dbd0b..7b52cf3 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ coverage yarn.lock /es/ package-lock.json +pnpm-lock.yaml .doc # dumi diff --git a/package.json b/package.json index 91652fc..576b331 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rc-component/mutate-observer", - "version": "1.1.0", + "version": "2.0.0", "description": "React MutateObserver Component", "keywords": [ "react", @@ -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", @@ -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": { diff --git a/src/MutateObserver.tsx b/src/MutateObserver.tsx index 435ed45..68b5d48 100644 --- a/src/MutateObserver.tsx +++ b/src/MutateObserver.tsx @@ -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'; @@ -46,7 +46,7 @@ const MutateObserver: React.FC = props => { return ( {canRef - ? React.cloneElement(children as any, { ref: mergedRef }) + ? React.cloneElement(children, { ref: mergedRef }) : children} ); diff --git a/src/useMutateObserver.tsx b/src/useMutateObserver.tsx index 4c31d1d..f0edd28 100644 --- a/src/useMutateObserver.tsx +++ b/src/useMutateObserver.tsx @@ -1,5 +1,5 @@ -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, @@ -7,11 +7,11 @@ const defaultOptions: MutationObserverInit = { attributeFilter: ['style', 'class'], }; -export default function useMutateObserver( +const useMutateObserver = ( nodeOrList: HTMLElement | HTMLElement[], callback: MutationCallback, options: MutationObserverInit = defaultOptions, -) { +) => { React.useEffect(() => { if (!canUseDom() || !nodeOrList) { return; @@ -33,4 +33,6 @@ export default function useMutateObserver( instance?.disconnect(); }; }, [options, nodeOrList]); -} +}; + +export default useMutateObserver; diff --git a/src/wrapper.ts b/src/wrapper.ts index f1f6ed3..3b0e4ab 100644 --- a/src/wrapper.ts +++ b/src/wrapper.ts @@ -1,10 +1,6 @@ import React from 'react'; -interface DomWrapperProps { - children: React.ReactNode; -} - -class DomWrapper extends React.Component { +class DomWrapper extends React.Component { render() { return this.props.children; }