diff --git a/now.json b/now.json deleted file mode 100644 index 0b0bc3f..0000000 --- a/now.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "version": 2, - "name": "rc-context", - "builds": [ - { - "src": "package.json", - "use": "@now/static-build", - "config": { "distDir": ".doc" } - } - ] -} diff --git a/package.json b/package.json index 71f8881..698d942 100644 --- a/package.json +++ b/package.json @@ -29,17 +29,17 @@ "coverage": "father test --coverage", "lint": "eslint src/ docs/ --ext .tsx,.ts,.jsx,.js", "now-build": "npm run build", - "prepublishOnly": "npm run compile && np --yolo --no-publish", + "prepublishOnly": "npm run compile && rc-np", "start": "dumi dev", "test": "rc-test", "tsc": "tsc --noEmit" }, "dependencies": { - "@babel/runtime": "^7.10.1", - "rc-util": "^5.27.0" + "@rc-component/util": "^1.3.0" }, "devDependencies": { - "@rc-component/father-plugin": "^1.0.0", + "@rc-component/father-plugin": "^2.0.2", + "@rc-component/np": "^1.0.4", "@types/jest": "^29.5.0", "@types/react": "^18.0.0", "@types/react-dom": "^18.0.0", @@ -51,7 +51,6 @@ "eslint-plugin-jest": "^28.2.0", "eslint-plugin-unicorn": "^52.0.0", "father": "^4.0.0", - "np": "^10.0.4", "rc-test": "^7.0.14", "react": "^18.0.0", "react-dom": "^18.0.0", diff --git a/src/Immutable.tsx b/src/Immutable.tsx index 3afb596..b8127d4 100644 --- a/src/Immutable.tsx +++ b/src/Immutable.tsx @@ -1,4 +1,4 @@ -import { supportRef } from 'rc-util/lib/ref'; +import { supportRef } from '@rc-component/util/lib/ref'; import * as React from 'react'; export type CompareProps> = ( @@ -6,6 +6,8 @@ export type CompareProps> = ( nextProps: Readonly>, ) => boolean; +type ImmutableProps> = Omit, 'ref'>; + /** * Create Immutable pair for `makeImmutable` and `responseImmutable`. */ @@ -32,10 +34,10 @@ export default function createImmutable() { function makeImmutable>( Component: T, shouldTriggerRender?: CompareProps, - ): T { + ): React.ComponentType> { const refAble = supportRef(Component); - const ImmutableComponent = function (props: any, ref: any) { + const ImmutableComponent = (props: ImmutableProps, ref: React.Ref) => { const refProps = refAble ? { ref } : {}; const renderTimesRef = React.useRef(0); const prevProps = React.useRef(props); @@ -43,13 +45,13 @@ export default function createImmutable() { // If parent has the context, we do not wrap it const mark = useImmutableMark(); if (mark !== null) { - return ; + return ; } if ( - // Always trigger re-render if not provide `notTriggerRender` + // Always trigger re-render if `shouldTriggerRender` is not provided !shouldTriggerRender || - shouldTriggerRender(prevProps.current, props) + shouldTriggerRender(prevProps.current as any, props as any) ) { renderTimesRef.current += 1; } @@ -58,7 +60,7 @@ export default function createImmutable() { return ( - + ); }; @@ -67,7 +69,9 @@ export default function createImmutable() { ImmutableComponent.displayName = `ImmutableRoot(${Component.displayName || Component.name})`; } - return refAble ? React.forwardRef(ImmutableComponent) : (ImmutableComponent as any); + return refAble + ? (React.forwardRef(ImmutableComponent) as React.ComponentType>) + : (ImmutableComponent as unknown as React.ComponentType>); } /** @@ -77,14 +81,13 @@ export default function createImmutable() { function responseImmutable>( Component: T, propsAreEqual?: CompareProps, - ): T { + ): React.ComponentType> { const refAble = supportRef(Component); - const ImmutableComponent = function (props: any, ref: any) { + const ImmutableComponent = (props: ImmutableProps, ref: React.Ref) => { const refProps = refAble ? { ref } : {}; useImmutableMark(); - - return ; + return ; }; if (process.env.NODE_ENV !== 'production') { @@ -94,8 +97,12 @@ export default function createImmutable() { } return refAble - ? React.memo(React.forwardRef(ImmutableComponent), propsAreEqual) - : (React.memo(ImmutableComponent, propsAreEqual) as any); + ? (React.memo(React.forwardRef(ImmutableComponent), propsAreEqual) as React.ComponentType< + React.ComponentProps + >) + : (React.memo(ImmutableComponent, propsAreEqual) as unknown as React.ComponentType< + React.ComponentProps + >); } return { diff --git a/src/context.tsx b/src/context.tsx index 68f6c57..3e2285e 100644 --- a/src/context.tsx +++ b/src/context.tsx @@ -1,6 +1,6 @@ -import useEvent from 'rc-util/lib/hooks/useEvent'; -import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; -import isEqual from 'rc-util/lib/isEqual'; +import useEvent from '@rc-component/util/lib/hooks/useEvent'; +import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import isEqual from '@rc-component/util/lib/isEqual'; import * as React from 'react'; import { unstable_batchedUpdates } from 'react-dom'; diff --git a/tsconfig.json b/tsconfig.json index 56cdc96..4966b43 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,15 +8,9 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": [ - "src/*" - ], - "@@/*": [ - ".dumi/tmp/*" - ], - "@rc-component/context": [ - "src/index.ts" - ] + "@/*": ["src/*"], + "@@/*": [".dumi/tmp/*"], + "@rc-component/context": ["src/index.ts"] } }, "include": [".dumi/**/*", ".dumirc.ts", "**/*.ts", "**/*.tsx"]