Skip to content

Commit

Permalink
fix: πŸ› replace defaultProps with useDefaultProps (#2644)
Browse files Browse the repository at this point in the history
* fix(πŸ› replace defaultprops with usedefaultprops): πŸ› replace defaultProps with useDefaultProps

* fix(revert type): revert type

* fix: revert to FC
  • Loading branch information
li-jia-nan authored Dec 5, 2023
1 parent a9c00ef commit 0a65978
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useConfig from '../hooks/useConfig';
import { pxCompat } from '../_util/helper';
import parseTNode from '../_util/parseTNode';
import { skeletonDefaultProps } from './defaultProps';
import useDefaultProps from '../hooks/useDefaultProps';

export type SkeletonProps = TdSkeletonProps & StyledProps & { children: React.ReactNode };

Expand All @@ -24,9 +25,9 @@ const ThemeMap: Record<TdSkeletonProps['theme'], SkeletonRowCol> = {
],
};

const Skeleton = (props: SkeletonProps) => {
const Skeleton: React.FC<SkeletonProps> = (originalProps) => {
const props = useDefaultProps<SkeletonProps>(originalProps, skeletonDefaultProps);
const { animation, loading, rowCol, theme, className, style, delay = 0, children } = props;

const { classPrefix } = useConfig();
const name = `${classPrefix}-skeleton`; // t-skeleton

Expand Down Expand Up @@ -70,7 +71,7 @@ const Skeleton = (props: SkeletonProps) => {
cols = [_cols as SkeletonRowColObj];
}

return cols.map((item, index) => (
return cols.map<React.ReactNode>((item, index) => (
<div key={index} className={getColItemClass(item)} style={getColItemStyle(item)}>
{parseTNode(item.content)}
</div>
Expand All @@ -80,7 +81,7 @@ const Skeleton = (props: SkeletonProps) => {
const renderRowCol = (_rowCol?: SkeletonRowCol) => {
const renderedRowCol: SkeletonRowCol = _rowCol || rowCol;

return renderedRowCol.map((item, index) => (
return renderedRowCol.map<React.ReactNode>((item, index) => (
<div key={index} className={`${name}__row`}>
{renderCols(item)}
</div>
Expand All @@ -104,7 +105,7 @@ const Skeleton = (props: SkeletonProps) => {
return <>{children}</>;
}

const childrenContent = [];
const childrenContent: React.ReactNode[] = [];
if (theme && !rowCol) {
childrenContent.push(renderRowCol(ThemeMap[theme]));
}
Expand All @@ -124,6 +125,5 @@ const Skeleton = (props: SkeletonProps) => {
};

Skeleton.displayName = 'Skeleton';
Skeleton.defaultProps = skeletonDefaultProps;

export default Skeleton;

0 comments on commit 0a65978

Please sign in to comment.