Skip to content

Commit

Permalink
feat: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang committed Feb 29, 2024
1 parent 4ce183c commit cd7c2a3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Dialog/Content/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames';
import { useComposeRef } from 'rc-util/lib/ref';
import React, { useRef } from 'react';
import React, { useMemo, useRef } from 'react';
import { RefContext } from '../../context';
import type { IDialogPropTypes } from '../../IDialogPropTypes';
import MemoChildren from './MemoChildren';
Expand Down Expand Up @@ -98,12 +98,15 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {
}


const closableObj =
typeof closable === 'object'
? closable
: closable
? { closeIcon: closeIcon ?? <span className={`${prefixCls}-close-x`} /> }
: {};
const closableObj = useMemo(() => {
if (typeof closable === 'object') {
return closable;
}
if (closable) {
return { closeIcon: closeIcon ?? <span className={`${prefixCls}-close-x`} /> };
}
return {};
}, [closable, closeIcon]);

const ariaProps = pickAttrs(closableObj, true);

Expand Down

0 comments on commit cd7c2a3

Please sign in to comment.