Skip to content

Commit

Permalink
fix: remove delete statement on render for react 18
Browse files Browse the repository at this point in the history
  • Loading branch information
yangpj17 committed Jun 14, 2022
1 parent 59dc90c commit 0cf9987
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/CSSMotionList.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* eslint react/prop-types: 0 */
import omit from 'rc-util/lib/omit';
import * as React from 'react';
import OriginCSSMotion from './CSSMotion';
import type { CSSMotionProps } from './CSSMotion';
import { supportTransition } from './util/motion';
import OriginCSSMotion from './CSSMotion';
import type { KeyObject } from './util/diff';
import {
diffKeys,
parseKeys,
STATUS_ADD,
STATUS_KEEP,
STATUS_REMOVE,
STATUS_REMOVED,
diffKeys,
parseKeys,
} from './util/diff';
import type { KeyObject } from './util/diff';
import { supportTransition } from './util/motion';
import pick from './util/pick';

const MOTION_PROP_NAMES = [
'eventProps',
Expand Down Expand Up @@ -127,16 +129,11 @@ export function genCSSMotionList(
} = this.props;

const Component = component || React.Fragment;

const motionProps: CSSMotionProps = {};
MOTION_PROP_NAMES.forEach(prop => {
motionProps[prop] = restProps[prop];
delete restProps[prop];
});
delete restProps.keys;
const motionProps = pick(restProps, MOTION_PROP_NAMES as any);
const componentProps = omit(restProps, MOTION_PROP_NAMES as any);

return (
<Component {...restProps}>
<Component {...componentProps}>
{keyEntities.map(({ status, ...eventProps }) => {
const visible = status === STATUS_ADD || status === STATUS_KEEP;
return (
Expand Down
14 changes: 14 additions & 0 deletions src/util/pick.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function pick<T extends object, K extends keyof T>(
obj: T,
fields: K[],
): Pick<T, K> {
const clone = {} as Pick<T, K>;

if (Array.isArray(fields)) {
fields.forEach(key => {
clone[key] = obj[key];
});
}

return clone;
}

0 comments on commit 0cf9987

Please sign in to comment.