Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove delete statement on render for react 18 #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}