Skip to content

Commit 24e6e2e

Browse files
authored
fix: fix usage of useMemo (#694)
1 parent 8b2aa71 commit 24e6e2e

File tree

2 files changed

+3
-20
lines changed

2 files changed

+3
-20
lines changed

src/components/collapse/index.tsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
22

33
import { classNames } from 'mo/common/className';
4-
import { isEqual } from 'lodash';
54
import { HTMLElementProps, UniqueId } from 'mo/common/types';
65
import { getDataAttributionsFromProps } from 'mo/common/dom';
76

@@ -16,12 +15,10 @@ import {
1615
collapsingClassName,
1716
defaultCollapseClassName,
1817
} from './base';
19-
20-
import { Pane } from '../split';
2118
import { IActionBarItemProps } from '../actionBar';
2219
import { Icon } from '../icon';
2320
import { Toolbar } from '../toolbar';
24-
import SplitPane, { ResizeStratygy } from '../split/SplitPane';
21+
import SplitPane, { ResizeStratygy, Pane } from '../split';
2522

2623
type RenderFunctionProps = (data: ICollapseItem) => React.ReactNode;
2724
export interface ICollapseItem extends HTMLElementProps {
@@ -265,11 +262,7 @@ export function Collapse({
265262
}
266263
});
267264

268-
const didChanged = !isEqual(res, resize);
269-
if (didChanged) {
270-
return res;
271-
}
272-
return resize;
265+
return res;
273266
}, [sizes]);
274267

275268
const dataAttrProps = getDataAttributionsFromProps(restProps);

src/components/split/SplitPane.tsx

+1-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, {
55
useRef,
66
useState,
77
} from 'react';
8-
import { isEqual, throttle } from 'lodash';
8+
import { throttle } from 'lodash';
99
import { cloneReactChildren } from 'mo/react';
1010
import { classNames } from 'mo/common/className';
1111
import { HTMLElementProps } from 'mo/common/types';
@@ -466,20 +466,13 @@ const SplitPane = ({
466466
limitedSizes.current[index] = registerLimitedSizes(child);
467467
return child.key || index;
468468
});
469-
// improving performance
470-
if (isEqual(nextKey, childrenKey)) {
471-
return childrenKey;
472-
}
473469
return nextKey;
474470
}, [children]);
475471

476472
// perform the task for recalculating resizable
477473
const allowResize = useMemo(() => {
478474
if (typeof propAllowResize === 'boolean') {
479475
const next = new Array(childrenKey.length).fill(propAllowResize);
480-
if (isEqual(next, allowResize)) {
481-
return allowResize;
482-
}
483476
return next;
484477
}
485478
const res: boolean[] = [];
@@ -490,9 +483,6 @@ const SplitPane = ({
490483
: propAllowResize[index]
491484
);
492485
}
493-
if (isEqual(res, allowResize)) {
494-
return allowResize;
495-
}
496486
return res;
497487
}, [childrenKey.length, propAllowResize]);
498488

0 commit comments

Comments
 (0)