Skip to content

Commit

Permalink
fix: type definition optimization & add key for useModal (#39701)
Browse files Browse the repository at this point in the history
* fix: add key for useModal

* fix

* fix

* fix lint

* revert
  • Loading branch information
li-jia-nan committed Dec 21, 2022
1 parent e5c60c8 commit b35fbcf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions components/message/useMessage.tsx
Expand Up @@ -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 ================================
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 5 additions & 4 deletions components/modal/useModal/index.tsx
Expand Up @@ -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 ==========================
Expand Down Expand Up @@ -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),
Expand All @@ -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;
7 changes: 5 additions & 2 deletions components/notification/useNotification.tsx
Expand Up @@ -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 ================================
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit b35fbcf

Please sign in to comment.