From 58a63bc77b7671896185e4cf3d398f62d0e1acb3 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 15 Mar 2020 02:04:15 +0800 Subject: [PATCH] refactor: use react-use simplify imports as tree shaking works --- src/components/FileExplorer.tsx | 3 +-- src/components/SideBar.tsx | 2 +- src/utils/hooks/useOnLocationChange.ts | 2 +- src/utils/hooks/usePrevious.ts | 9 --------- 4 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 src/utils/hooks/usePrevious.ts diff --git a/src/components/FileExplorer.tsx b/src/components/FileExplorer.tsx index c7db4f2..b5f0509 100644 --- a/src/components/FileExplorer.tsx +++ b/src/components/FileExplorer.tsx @@ -7,11 +7,10 @@ import { connect } from 'driver/connect' import { FileExplorerCore } from 'driver/core' import { ConnectorState, Props } from 'driver/core/FileExplorer' import * as React from 'react' -import useEvent from 'react-use/esm/useEvent' +import { useEvent, usePrevious } from 'react-use' import { FixedSizeList as List, ListChildComponentProps, ListProps } from 'react-window' import { cx } from 'utils/cx' import { useOnLocationChange } from 'utils/hooks/useOnLocationChange' -import { usePrevious } from 'utils/hooks/usePrevious' import { getCurrentPath } from 'utils/URLHelper' import { TreeNode, VisibleNodes } from 'utils/VisibleNodesGenerator' import { Icon } from './Icon' diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index 0609c99..8085511 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -11,7 +11,7 @@ import { SideBarCore } from 'driver/core' import { ConnectorState, Props } from 'driver/core/SideBar' import { oauth } from 'env' import * as React from 'react' -import useEvent from 'react-use/esm/useEvent' +import { useEvent } from 'react-use' import { cx } from 'utils/cx' import * as DOMHelper from 'utils/DOMHelper' import { JSONRequest, parseURLSearch } from 'utils/general' diff --git a/src/utils/hooks/useOnLocationChange.ts b/src/utils/hooks/useOnLocationChange.ts index 685aa47..88ecd10 100644 --- a/src/utils/hooks/useOnLocationChange.ts +++ b/src/utils/hooks/useOnLocationChange.ts @@ -1,5 +1,5 @@ import * as React from 'react' -import useLocation from 'react-use/esm/useLocation' +import { useLocation } from 'react-use' export function useOnLocationChange( callback: React.EffectCallback, diff --git a/src/utils/hooks/usePrevious.ts b/src/utils/hooks/usePrevious.ts deleted file mode 100644 index 1d4dd4b..0000000 --- a/src/utils/hooks/usePrevious.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as React from 'react' - -export function usePrevious(newValue: T) { - const previousRef = React.useRef(newValue) - React.useEffect(() => { - previousRef.current = newValue - }) - return previousRef.current -}