Skip to content

Commit

Permalink
perf: reduce InputTag time complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerleung0411 authored and yinkaihui committed Jun 11, 2024
1 parent 01d24d9 commit bf99b3e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion components/InputTag/input-tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,13 @@ function InputTag(baseProps: InputTagProps<string | ObjectValueType>, ref) {
// CSSTransition needs to be a direct child of TransitionGroup, otherwise the animation will NOT work
// https://github.com/arco-design/arco-design/issues/622
const childrenTagWithAnimation = useMemo<ReactNode[]>(() => {
// a map for duplication check, avoid O(n^2) complexity.
const valueCountMap: Record<string, number | undefined> = {};
const items = value.map((x, i) => {
// Check whether two tags have same value. If so, set different key for them to avoid only rendering one tag.
const isRepeat = value.findIndex((item) => item.value === x.value) !== i;
const valueCount = valueCountMap[x.value] || 0;
const isRepeat = valueCount >= 1;
valueCountMap[x.value] = valueCount + 1;
const { dom: eleTag, valueKey } = mergedRenderTag(x, i);
return React.isValidElement(eleTag) ? (
<CSSTransition
Expand Down

0 comments on commit bf99b3e

Please sign in to comment.