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/docs/examples/getContainer.tsx b/docs/examples/getContainer.tsx index 1cf2c0b..b8ee9b1 100644 --- a/docs/examples/getContainer.tsx +++ b/docs/examples/getContainer.tsx @@ -10,7 +10,7 @@ const Content = (): React.ReactElement => { }; export default () => { - const divRef = React.useRef(); + const divRef = React.useRef(null); return (
((props, ref) => { const renderInline = mergedContainer === false || inlineMock(); let reffedChildren = children; + if (ref) { - reffedChildren = React.cloneElement(children as any, { - ref: mergedRef, - }); + reffedChildren = React.cloneElement(children as any, { ref: mergedRef }); } return ( diff --git a/src/useDom.tsx b/src/useDom.tsx index 784aaae..a64b77d 100644 --- a/src/useDom.tsx +++ b/src/useDom.tsx @@ -1,19 +1,19 @@ import * as React from 'react'; -import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; -import canUseDom from 'rc-util/lib/Dom/canUseDom'; +import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import canUseDom from '@rc-component/util/lib/Dom/canUseDom'; import OrderContext from './Context'; import type { QueueCreate } from './Context'; -const EMPTY_LIST = []; +const EMPTY_LIST: VoidFunction[] = []; /** * Will add `div` to document. Nest call will keep order * @param render Render DOM in document */ -export default function useDom( +const useDom = ( render: boolean, debug?: string, -): [HTMLDivElement, QueueCreate] { +): [HTMLDivElement, QueueCreate] => { const [ele] = React.useState(() => { if (!canUseDom()) { return null; @@ -82,4 +82,6 @@ export default function useDom( }, [queue]); return [ele, mergedQueueCreate]; -} +}; + +export default useDom; diff --git a/src/useScrollLocker.tsx b/src/useScrollLocker.tsx index febc78b..e386f30 100644 --- a/src/useScrollLocker.tsx +++ b/src/useScrollLocker.tsx @@ -1,14 +1,14 @@ import * as React from 'react'; -import { updateCSS, removeCSS } from 'rc-util/lib/Dom/dynamicCSS'; -import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect'; -import { getTargetScrollBarSize } from 'rc-util/lib/getScrollBarSize'; +import { updateCSS, removeCSS } from '@rc-component/util/lib/Dom/dynamicCSS'; +import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect'; +import { getTargetScrollBarSize } from '@rc-component/util/lib/getScrollBarSize'; import { isBodyOverflowing } from './util'; -const UNIQUE_ID = `rc-util-locker-${Date.now()}`; +const UNIQUE_ID = `@rc-component/util-locker-${Date.now()}`; let uuid = 0; -export default function useScrollLocker(lock?: boolean) { +const useScrollLocker = (lock?: boolean) => { const mergedLock = !!lock; const [id] = React.useState(() => { uuid += 1; @@ -36,4 +36,6 @@ html body { removeCSS(id); }; }, [mergedLock, id]); -} +}; + +export default useScrollLocker; diff --git a/tests/index.test.tsx b/tests/index.test.tsx index c433ea0..5e3243f 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -13,7 +13,7 @@ jest.mock('../src/util', () => { }); // Revert `useLayoutEffect` back to real one since we should keep order for test -jest.mock('rc-util/lib/hooks/useLayoutEffect', () => { +jest.mock('@rc-component/util/lib/hooks/useLayoutEffect', () => { const origin = jest.requireActual('react'); return origin.useLayoutEffect; }); @@ -72,7 +72,7 @@ describe('Portal', () => { }; const Demo = () => { - const divRef = React.useRef(); + const divRef = React.useRef(null); return (
@@ -231,7 +231,7 @@ describe('Portal', () => { let checked = false; const Demo = ({ open }: { open?: boolean }) => { - const pRef = React.useRef(); + const pRef = React.useRef(null); React.useEffect(() => { if (open) { diff --git a/tests/webkit.test.tsx b/tests/webkit.test.tsx index 48757a2..7fc95ca 100644 --- a/tests/webkit.test.tsx +++ b/tests/webkit.test.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { render } from '@testing-library/react'; import Portal from '../src'; -import { updateCSS } from 'rc-util/lib/Dom/dynamicCSS'; jest.mock('../src/util', () => { const origin = jest.requireActual('../src/util'); @@ -12,14 +11,14 @@ jest.mock('../src/util', () => { }); // Revert `useLayoutEffect` back to real one since we should keep order for test -jest.mock('rc-util/lib/hooks/useLayoutEffect', () => { +jest.mock('@rc-component/util/lib/hooks/useLayoutEffect', () => { const origin = jest.requireActual('react'); return origin.useLayoutEffect; }); // Revert `useLayoutEffect` back to real one since we should keep order for test -jest.mock('rc-util/lib/getScrollBarSize', () => { - const origin = jest.requireActual('rc-util/lib/getScrollBarSize'); +jest.mock('@rc-component/util/lib/getScrollBarSize', () => { + const origin = jest.requireActual('@rc-component/util/lib/getScrollBarSize'); return { ...origin,