Skip to content

Commit 0cf9987

Browse files
author
yangpj17
committed
fix: remove delete statement on render for react 18
1 parent 59dc90c commit 0cf9987

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/CSSMotionList.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/* eslint react/prop-types: 0 */
2+
import omit from 'rc-util/lib/omit';
23
import * as React from 'react';
3-
import OriginCSSMotion from './CSSMotion';
44
import type { CSSMotionProps } from './CSSMotion';
5-
import { supportTransition } from './util/motion';
5+
import OriginCSSMotion from './CSSMotion';
6+
import type { KeyObject } from './util/diff';
67
import {
8+
diffKeys,
9+
parseKeys,
710
STATUS_ADD,
811
STATUS_KEEP,
912
STATUS_REMOVE,
1013
STATUS_REMOVED,
11-
diffKeys,
12-
parseKeys,
1314
} from './util/diff';
14-
import type { KeyObject } from './util/diff';
15+
import { supportTransition } from './util/motion';
16+
import pick from './util/pick';
1517

1618
const MOTION_PROP_NAMES = [
1719
'eventProps',
@@ -127,16 +129,11 @@ export function genCSSMotionList(
127129
} = this.props;
128130

129131
const Component = component || React.Fragment;
130-
131-
const motionProps: CSSMotionProps = {};
132-
MOTION_PROP_NAMES.forEach(prop => {
133-
motionProps[prop] = restProps[prop];
134-
delete restProps[prop];
135-
});
136-
delete restProps.keys;
132+
const motionProps = pick(restProps, MOTION_PROP_NAMES as any);
133+
const componentProps = omit(restProps, MOTION_PROP_NAMES as any);
137134

138135
return (
139-
<Component {...restProps}>
136+
<Component {...componentProps}>
140137
{keyEntities.map(({ status, ...eventProps }) => {
141138
const visible = status === STATUS_ADD || status === STATUS_KEEP;
142139
return (

src/util/pick.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default function pick<T extends object, K extends keyof T>(
2+
obj: T,
3+
fields: K[],
4+
): Pick<T, K> {
5+
const clone = {} as Pick<T, K>;
6+
7+
if (Array.isArray(fields)) {
8+
fields.forEach(key => {
9+
clone[key] = obj[key];
10+
});
11+
}
12+
13+
return clone;
14+
}

0 commit comments

Comments
 (0)