From 343fc01ede61884b7e131bb39f1ed0b8b0f41a38 Mon Sep 17 00:00:00 2001 From: Chuns Chen Date: Wed, 14 Dec 2022 10:44:19 +0800 Subject: [PATCH] fix: react defaultProps warning (#363) --- src/Drawer.tsx | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Drawer.tsx b/src/Drawer.tsx index e676158..7e00da5 100644 --- a/src/Drawer.tsx +++ b/src/Drawer.tsx @@ -17,7 +17,25 @@ export interface DrawerProps getContainer?: PortalProps['getContainer']; } -const Drawer: React.FC = 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 => { + const props = { + ...defaultProps, + ...drawerProps, + }; const { open, getContainer, @@ -65,20 +83,6 @@ const Drawer: React.FC = 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'; }