Skip to content

Commit

Permalink
perf: code perf
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Jan 8, 2022
1 parent 09d1614 commit d8c91f8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { option } from './config';
import isEmpty from 'lodash.isempty';
import useThrottleEffect from './utils/useThrottleEffect';
import useDebounceFn from './utils/useDebounceFn';
import { depthFirstSearch, ResizableUniqIdPrefix } from './utils';
import { depthFirstSearch } from './utils';
import useSafeState from './utils/useSafeState';
import useLocalColumns from './utils/useLocalColumns';
import useGetDataIndexColumns, { GETKEY } from './utils/useGetDataIndexColumns';
import useGetDataIndexColumns, { GETKEY, ResizableUniqIdPrefix } from './utils/useGetDataIndexColumns';

export type ColumnsState = {
width: number;
Expand Down
2 changes: 0 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ export function depthFirstSearch<T extends Record<string, any> & { children?: T[

return c;
}

export const ResizableUniqIdPrefix = 'resizable-table-id';
7 changes: 4 additions & 3 deletions src/utils/useGetDataIndexColumns.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useMemo } from 'react';
import { ResizableUniqIdPrefix } from '.';
import React from 'react';
import { ColumnOriginType } from '..';
import useMemoizedFn from './useMemoizedFn';

export const GETKEY = 'dataIndex';

export const ResizableUniqIdPrefix = 'resizable-table-id';

export function getUniqueId(index: number) {
return `${ResizableUniqIdPrefix}-${index}`;
}
Expand All @@ -27,7 +28,7 @@ function useGetDataIndexColumns<T extends ColumnOriginType<T>>(columns: T[] | un
return c;
});

const dataIndexColumns = useMemo(() => getColumns(columns), [getColumns]) as T[] | undefined;
const dataIndexColumns = React.useMemo(() => getColumns(columns), [getColumns]) as T[] | undefined;

return dataIndexColumns || columns;
}
Expand Down

0 comments on commit d8c91f8

Please sign in to comment.