diff --git a/components/message/index.tsx b/components/message/index.tsx index a9c5e134577e..7d2f1fdf201a 100755 --- a/components/message/index.tsx +++ b/components/message/index.tsx @@ -1,9 +1,9 @@ 'use client'; -import { render } from 'rc-util/lib/React/render'; import * as React from 'react'; +import { render } from 'rc-util/lib/React/render'; + import ConfigProvider, { globalConfig, warnContext } from '../config-provider'; -import PurePanel from './PurePanel'; import type { ArgsProps, ConfigOptions, @@ -12,6 +12,7 @@ import type { NoticeType, TypeOpen, } from './interface'; +import PurePanel from './PurePanel'; import useMessage, { useInternalMessage } from './useMessage'; import { wrapPromiseFn } from './util'; @@ -70,7 +71,7 @@ function getGlobalContext() { return { prefixCls: mergedPrefixCls, - container: mergedContainer, + getContainer: () => mergedContainer!, duration, rtl, maxCount, @@ -84,20 +85,7 @@ interface GlobalHolderRef { } const GlobalHolder = React.forwardRef((_, ref) => { - const initializeMessageConfig: () => ConfigOptions = () => { - const { prefixCls, container, maxCount, duration, rtl, top } = getGlobalContext(); - - return { - prefixCls, - getContainer: () => container!, - maxCount, - duration, - rtl, - top, - }; - }; - - const [messageConfig, setMessageConfig] = React.useState(initializeMessageConfig); + const [messageConfig, setMessageConfig] = React.useState(getGlobalContext); const [api, holder] = useInternalMessage(messageConfig); @@ -107,7 +95,7 @@ const GlobalHolder = React.forwardRef((_, ref) => { const theme = global.getTheme(); const sync = () => { - setMessageConfig(initializeMessageConfig); + setMessageConfig(getGlobalContext); }; React.useEffect(sync, []); diff --git a/components/notification/index.tsx b/components/notification/index.tsx index dd852fea5659..21c70ba69775 100755 --- a/components/notification/index.tsx +++ b/components/notification/index.tsx @@ -1,10 +1,11 @@ 'use client'; -import { render } from 'rc-util/lib/React/render'; import * as React from 'react'; +import { render } from 'rc-util/lib/React/render'; + import ConfigProvider, { globalConfig, warnContext } from '../config-provider'; -import PurePanel from './PurePanel'; import type { ArgsProps, GlobalConfigProps, NotificationInstance } from './interface'; +import PurePanel from './PurePanel'; import useNotification, { useInternalNotification } from './useNotification'; let notification: GlobalNotification | null = null; @@ -45,7 +46,7 @@ function getGlobalContext() { return { prefixCls: mergedPrefixCls, - container: mergedContainer, + getContainer: () => mergedContainer!, rtl, maxCount, top, @@ -59,21 +60,10 @@ interface GlobalHolderRef { } const GlobalHolder = React.forwardRef((_, ref) => { - const [prefixCls, setPrefixCls] = React.useState(); - const [container, setContainer] = React.useState(); - const [maxCount, setMaxCount] = React.useState(); - const [rtl, setRTL] = React.useState(); - const [top, setTop] = React.useState(); - const [bottom, setBottom] = React.useState(); - - const [api, holder] = useInternalNotification({ - prefixCls, - getContainer: () => container!, - maxCount, - rtl, - top, - bottom, - }); + const [notificationConfig, setNotificationConfig] = + React.useState(getGlobalContext); + + const [api, holder] = useInternalNotification(notificationConfig); const global = globalConfig(); const rootPrefixCls = global.getRootPrefixCls(); @@ -81,21 +71,7 @@ const GlobalHolder = React.forwardRef((_, ref) => { const theme = global.getTheme(); const sync = () => { - const { - prefixCls: nextGlobalPrefixCls, - container: nextGlobalContainer, - maxCount: nextGlobalMaxCount, - rtl: nextGlobalRTL, - top: nextTop, - bottom: nextBottom, - } = getGlobalContext(); - - setPrefixCls(nextGlobalPrefixCls); - setContainer(nextGlobalContainer); - setMaxCount(nextGlobalMaxCount); - setRTL(nextGlobalRTL); - setTop(nextTop); - setBottom(nextBottom); + setNotificationConfig(getGlobalContext); }; React.useEffect(sync, []);