From ced837e78f264cc976c6a3e46d878e25680a6e4b Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Wed, 26 Jul 2023 14:11:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20replace=20defaultProps=20?= =?UTF-8?q?with=20useDefaultProps=20(#2377)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 🐛 replace defaultProps with useDefaultProps 🐛 replace defaultProps with useDefaultProps * fix: 🐛 NotificationProps --- src/notification/Notification.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/notification/Notification.tsx b/src/notification/Notification.tsx index e7c7f0881..e94026544 100644 --- a/src/notification/Notification.tsx +++ b/src/notification/Notification.tsx @@ -13,12 +13,13 @@ import useGlobalIcon from '../hooks/useGlobalIcon'; import { NotificationInstance, TdNotificationProps } from './type'; import { StyledProps } from '../common'; import { notificationDefaultProps } from './defaultProps'; +import useDefaultProps from '../hooks/useDefaultProps'; export interface NotificationProps extends TdNotificationProps, StyledProps { id?: string; } -export const Notification = forwardRef((props, ref) => { +export const Notification = forwardRef((props, ref) => { const { title, content, @@ -32,7 +33,7 @@ export const Notification = forwardRef((props, ref) => { style, className, id, - } = props; + } = useDefaultProps(props, notificationDefaultProps); const { classPrefix } = useConfig(); const baseClassPrefix = `${classPrefix}-notification`; @@ -43,11 +44,12 @@ export const Notification = forwardRef((props, ref) => { }); const remove = useContext(NotificationRemoveContext); - React.useImperativeHandle(ref as React.Ref, () => ({ close: () => remove(id) })); + + React.useImperativeHandle(ref, () => ({ close: () => remove(id) })); /* eslint-disable react-hooks/exhaustive-deps */ React.useEffect(() => { - let timer; + let timer: NodeJS.Timeout; if (duration > 0) { timer = setTimeout(() => { clearTimeout(timer); @@ -55,12 +57,16 @@ export const Notification = forwardRef((props, ref) => { }, duration); } return () => { - if (timer) clearTimeout(timer); + if (timer) { + clearTimeout(timer); + } }; }, []); const renderIcon = () => { - if (typeof icon === 'boolean' && !icon) return null; + if (typeof icon === 'boolean' && !icon) { + return null; + } const IconWrapper = ({ children }) =>
{children}
; @@ -132,6 +138,5 @@ export const Notification = forwardRef((props, ref) => { }); Notification.displayName = 'Notification'; -Notification.defaultProps = notificationDefaultProps; export default Notification;