Skip to content

Commit

Permalink
fix: react defaultProps warning (#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
chunsch authored Dec 14, 2022
1 parent 3268514 commit 343fc01
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,25 @@ export interface DrawerProps
getContainer?: PortalProps['getContainer'];
}

const Drawer: React.FC<DrawerProps> = props => {
// Default Value.
// Since spread with default value will make this all over components.
// Let's maintain this in one place.
const defaultProps = {
open: false,
prefixCls: 'rc-drawer',
placement: 'right' as Placement,
autoFocus: true,
keyboard: true,
width: 378,
mask: true,
maskClosable: true,
};

const Drawer: React.FC<DrawerProps> = drawerProps => {
const props = {
...defaultProps,
...drawerProps,
};
const {
open,
getContainer,
Expand Down Expand Up @@ -65,20 +83,6 @@ const Drawer: React.FC<DrawerProps> = props => {
);
};

// Default Value.
// Since spread with default value will make this all over components.
// Let's maintain this in one place.
Drawer.defaultProps = {
open: false,
prefixCls: 'rc-drawer',
placement: 'right',
autoFocus: true,
keyboard: true,
width: 378,
mask: true,
maskClosable: true,
};

if (process.env.NODE_ENV !== 'production') {
Drawer.displayName = 'Drawer';
}
Expand Down

0 comments on commit 343fc01

Please sign in to comment.