mirror of
https://github.com/ant-design/ant-design.git
synced 2026-02-09 02:49:18 +08:00
fix: type definition optimization & add key for useModal (#39701)
* fix: add key for useModal * fix * fix * fix lint * revert
This commit is contained in:
@@ -98,7 +98,7 @@ let keyIndex = 0;
|
||||
|
||||
export function useInternalMessage(
|
||||
notificationConfig?: HolderProps,
|
||||
): [MessageInstance, React.ReactElement] {
|
||||
): readonly [MessageInstance, React.ReactElement] {
|
||||
const holderRef = React.useRef<HolderRef>(null);
|
||||
|
||||
// ================================ API ================================
|
||||
@@ -212,7 +212,10 @@ export function useInternalMessage(
|
||||
}, []);
|
||||
|
||||
// ============================== Return ===============================
|
||||
return [wrapAPI, <Holder key="message-holder" {...notificationConfig} ref={holderRef} />];
|
||||
return [
|
||||
wrapAPI,
|
||||
<Holder key="message-holder" {...notificationConfig} ref={holderRef} />,
|
||||
] as const;
|
||||
}
|
||||
|
||||
export default function useMessage(notificationConfig?: ConfigOptions) {
|
||||
|
||||
@@ -27,7 +27,7 @@ const ElementsHolder = React.memo(
|
||||
}),
|
||||
);
|
||||
|
||||
export default function useModal(): [Omit<ModalStaticFunctions, 'warn'>, React.ReactElement] {
|
||||
function useModal(): readonly [Omit<ModalStaticFunctions, 'warn'>, React.ReactElement] {
|
||||
const holderRef = React.useRef<ElementsHolderRef>(null);
|
||||
|
||||
// ========================== Effect ==========================
|
||||
@@ -94,7 +94,7 @@ export default function useModal(): [Omit<ModalStaticFunctions, 'warn'>, React.R
|
||||
[],
|
||||
);
|
||||
|
||||
const fns = React.useMemo(
|
||||
const fns = React.useMemo<Omit<ModalStaticFunctions, 'warn'>>(
|
||||
() => ({
|
||||
info: getConfirmFunc(withInfo),
|
||||
success: getConfirmFunc(withSuccess),
|
||||
@@ -105,6 +105,7 @@ export default function useModal(): [Omit<ModalStaticFunctions, 'warn'>, React.R
|
||||
[],
|
||||
);
|
||||
|
||||
// eslint-disable-next-line react/jsx-key
|
||||
return [fns, <ElementsHolder ref={holderRef} />];
|
||||
return [fns, <ElementsHolder key="modal-holder" ref={holderRef} />] as const;
|
||||
}
|
||||
|
||||
export default useModal;
|
||||
|
||||
@@ -84,7 +84,7 @@ const Holder = React.forwardRef<HolderRef, HolderProps>((props, ref) => {
|
||||
// ==============================================================================
|
||||
export function useInternalNotification(
|
||||
notificationConfig?: HolderProps,
|
||||
): [NotificationInstance, React.ReactElement] {
|
||||
): readonly [NotificationInstance, React.ReactElement] {
|
||||
const holderRef = React.useRef<HolderRef>(null);
|
||||
|
||||
// ================================ API ================================
|
||||
@@ -160,7 +160,10 @@ export function useInternalNotification(
|
||||
}, []);
|
||||
|
||||
// ============================== Return ===============================
|
||||
return [wrapAPI, <Holder key="notification-holder" {...notificationConfig} ref={holderRef} />];
|
||||
return [
|
||||
wrapAPI,
|
||||
<Holder key="notification-holder" {...notificationConfig} ref={holderRef} />,
|
||||
] as const;
|
||||
}
|
||||
|
||||
export default function useNotification(notificationConfig?: NotificationConfig) {
|
||||
|
||||
Reference in New Issue
Block a user