Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions src/hooks/useNotification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from 'react';
import type { NotificationsProps, NotificationsRef } from '../Notifications';
import Notifications from '../Notifications';
import type { OpenConfig, Placement, StackConfig } from '../interface';
import { useEvent } from 'rc-util';

const defaultGetContainer = () => document.body;

Expand Down Expand Up @@ -107,34 +108,29 @@ export default function useNotification(

const [taskQueue, setTaskQueue] = React.useState<Task[]>([]);

// memorized shareConfig
const { closeIcon, closable, duration, showProgress, pauseOnHover } = shareConfig;
const memoShareConfig = React.useMemo<typeof shareConfig>(() => {
return {
...shareConfig,
};
}, [closeIcon, closable, duration, showProgress, pauseOnHover]);
const open = useEvent<NotificationAPI['open']>((config) => {
const mergedConfig = mergeConfig(shareConfig, config);
if (mergedConfig.key === null || mergedConfig.key === undefined) {
mergedConfig.key = `rc-notification-${uniqueKey}`;
uniqueKey += 1;
}

// ========================= Refs =========================
const api = React.useMemo<NotificationAPI>(() => {
return {
open: (config) => {
const mergedConfig = mergeConfig(memoShareConfig, config);
if (mergedConfig.key === null || mergedConfig.key === undefined) {
mergedConfig.key = `rc-notification-${uniqueKey}`;
uniqueKey += 1;
}
setTaskQueue((queue) => [...queue, { type: 'open', config: mergedConfig }]);
});

setTaskQueue((queue) => [...queue, { type: 'open', config: mergedConfig }]);
},
// ========================= Refs =========================
const api = React.useMemo<NotificationAPI>(
() => ({
open: open,
close: (key) => {
setTaskQueue((queue) => [...queue, { type: 'close', key }]);
},
destroy: () => {
setTaskQueue((queue) => [...queue, { type: 'destroy' }]);
},
};
}, [memoShareConfig]);
}),
[],
);

// ======================= Container ======================
// React 18 should all in effect that we will check container in each render
Expand Down