From 033b3702841718717363113eaad910d9283c37a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 21 Dec 2022 10:22:07 +0800 Subject: [PATCH 1/5] fix: add key for useModal --- components/message/useMessage.tsx | 7 +++++-- components/modal/useModal/index.tsx | 9 +++++---- components/notification/useNotification.tsx | 7 +++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/components/message/useMessage.tsx b/components/message/useMessage.tsx index 529f94cda737..2b39e1409ac2 100644 --- a/components/message/useMessage.tsx +++ b/components/message/useMessage.tsx @@ -98,7 +98,7 @@ let keyIndex = 0; export function useInternalMessage( notificationConfig?: HolderProps, -): [MessageInstance, React.ReactElement] { +): readonly [MessageInstance, React.ReactNode] { const holderRef = React.useRef(null); // ================================ API ================================ @@ -212,7 +212,10 @@ export function useInternalMessage( }, []); // ============================== Return =============================== - return [wrapAPI, ]; + return [ + wrapAPI, + , + ] as const; } export default function useMessage(notificationConfig?: ConfigOptions) { diff --git a/components/modal/useModal/index.tsx b/components/modal/useModal/index.tsx index 5b6e31d1dc1a..eef8dd3653d8 100644 --- a/components/modal/useModal/index.tsx +++ b/components/modal/useModal/index.tsx @@ -27,7 +27,7 @@ const ElementsHolder = React.memo( }), ); -export default function useModal(): [Omit, React.ReactElement] { +function useModal(): readonly [Omit, React.ReactNode] { const holderRef = React.useRef(null); // ========================== Effect ========================== @@ -94,7 +94,7 @@ export default function useModal(): [Omit, React.R [], ); - const fns = React.useMemo( + const fns = React.useMemo>( () => ({ info: getConfirmFunc(withInfo), success: getConfirmFunc(withSuccess), @@ -105,6 +105,7 @@ export default function useModal(): [Omit, React.R [], ); - // eslint-disable-next-line react/jsx-key - return [fns, ]; + return [fns, ] as const; } + +export default useModal; diff --git a/components/notification/useNotification.tsx b/components/notification/useNotification.tsx index c61c80aff32b..7bfa7d3896dd 100644 --- a/components/notification/useNotification.tsx +++ b/components/notification/useNotification.tsx @@ -84,7 +84,7 @@ const Holder = React.forwardRef((props, ref) => { // ============================================================================== export function useInternalNotification( notificationConfig?: HolderProps, -): [NotificationInstance, React.ReactElement] { +): readonly [NotificationInstance, React.ReactNode] { const holderRef = React.useRef(null); // ================================ API ================================ @@ -160,7 +160,10 @@ export function useInternalNotification( }, []); // ============================== Return =============================== - return [wrapAPI, ]; + return [ + wrapAPI, + , + ] as const; } export default function useNotification(notificationConfig?: NotificationConfig) { From bc8a46f8a88396f0b93a572e59a811e16bf7c6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 21 Dec 2022 10:33:22 +0800 Subject: [PATCH 2/5] fix --- components/modal/useModal/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/modal/useModal/index.tsx b/components/modal/useModal/index.tsx index eef8dd3653d8..1630807f4362 100644 --- a/components/modal/useModal/index.tsx +++ b/components/modal/useModal/index.tsx @@ -105,7 +105,7 @@ function useModal(): readonly [Omit, React.ReactNo [], ); - return [fns, ] as const; + return [fns, ] as const; } export default useModal; From 24a6f8431cdedfedd712ad5f16c1d1bfab3c8e13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 21 Dec 2022 10:33:29 +0800 Subject: [PATCH 3/5] fix --- components/modal/useModal/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/modal/useModal/index.tsx b/components/modal/useModal/index.tsx index 1630807f4362..eef8dd3653d8 100644 --- a/components/modal/useModal/index.tsx +++ b/components/modal/useModal/index.tsx @@ -105,7 +105,7 @@ function useModal(): readonly [Omit, React.ReactNo [], ); - return [fns, ] as const; + return [fns, ] as const; } export default useModal; From f1d5b7eec2e66fc7fddd0e36967000555522e228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 21 Dec 2022 10:42:49 +0800 Subject: [PATCH 4/5] fix lint --- components/message/__tests__/hooks.test.tsx | 5 +++-- components/notification/__tests__/hooks.test.tsx | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/components/message/__tests__/hooks.test.tsx b/components/message/__tests__/hooks.test.tsx index f2de6616a4ad..37bbe8056c15 100644 --- a/components/message/__tests__/hooks.test.tsx +++ b/components/message/__tests__/hooks.test.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react/jsx-no-useless-fragment */ /* eslint-disable jsx-a11y/control-has-associated-label */ import React from 'react'; import { act } from 'react-dom/test-utils'; @@ -233,7 +234,7 @@ describe('message.hooks', () => { it('warning if user call update in render', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - const Demo = () => { + const Demo: React.FC = () => { const [api, holder] = message.useMessage(); const calledRef = React.useRef(false); @@ -244,7 +245,7 @@ describe('message.hooks', () => { calledRef.current = true; } - return holder; + return <>{holder}; }; render(); diff --git a/components/notification/__tests__/hooks.test.tsx b/components/notification/__tests__/hooks.test.tsx index 10a140dbff8c..525c3bc3d06a 100644 --- a/components/notification/__tests__/hooks.test.tsx +++ b/components/notification/__tests__/hooks.test.tsx @@ -1,3 +1,4 @@ +/* eslint-disable react/jsx-no-useless-fragment */ import React from 'react'; import { render, fireEvent, pureRender } from '../../../tests/utils'; import notification from '..'; @@ -118,7 +119,7 @@ describe('notification.hooks', () => { }); }, []); - return holder; + return <>{holder}; }; render(); @@ -129,7 +130,7 @@ describe('notification.hooks', () => { it('warning if user call update in render', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - const Demo = () => { + const Demo: React.FC = () => { const [api, holder] = notification.useNotification(); const calledRef = React.useRef(false); @@ -141,7 +142,7 @@ describe('notification.hooks', () => { calledRef.current = true; } - return holder; + return <>{holder}; }; render(); From a1a55c2773736f062b88af30ed47e8205a63d618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A0=97=E5=98=89=E7=94=B7?= <574980606@qq.com> Date: Wed, 21 Dec 2022 10:53:58 +0800 Subject: [PATCH 5/5] revert --- components/message/__tests__/hooks.test.tsx | 5 ++--- components/message/useMessage.tsx | 2 +- components/modal/useModal/index.tsx | 2 +- components/notification/__tests__/hooks.test.tsx | 7 +++---- components/notification/useNotification.tsx | 2 +- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/components/message/__tests__/hooks.test.tsx b/components/message/__tests__/hooks.test.tsx index 37bbe8056c15..f2de6616a4ad 100644 --- a/components/message/__tests__/hooks.test.tsx +++ b/components/message/__tests__/hooks.test.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/jsx-no-useless-fragment */ /* eslint-disable jsx-a11y/control-has-associated-label */ import React from 'react'; import { act } from 'react-dom/test-utils'; @@ -234,7 +233,7 @@ describe('message.hooks', () => { it('warning if user call update in render', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - const Demo: React.FC = () => { + const Demo = () => { const [api, holder] = message.useMessage(); const calledRef = React.useRef(false); @@ -245,7 +244,7 @@ describe('message.hooks', () => { calledRef.current = true; } - return <>{holder}; + return holder; }; render(); diff --git a/components/message/useMessage.tsx b/components/message/useMessage.tsx index 2b39e1409ac2..62d6592a0aa2 100644 --- a/components/message/useMessage.tsx +++ b/components/message/useMessage.tsx @@ -98,7 +98,7 @@ let keyIndex = 0; export function useInternalMessage( notificationConfig?: HolderProps, -): readonly [MessageInstance, React.ReactNode] { +): readonly [MessageInstance, React.ReactElement] { const holderRef = React.useRef(null); // ================================ API ================================ diff --git a/components/modal/useModal/index.tsx b/components/modal/useModal/index.tsx index eef8dd3653d8..db9b6e781814 100644 --- a/components/modal/useModal/index.tsx +++ b/components/modal/useModal/index.tsx @@ -27,7 +27,7 @@ const ElementsHolder = React.memo( }), ); -function useModal(): readonly [Omit, React.ReactNode] { +function useModal(): readonly [Omit, React.ReactElement] { const holderRef = React.useRef(null); // ========================== Effect ========================== diff --git a/components/notification/__tests__/hooks.test.tsx b/components/notification/__tests__/hooks.test.tsx index 525c3bc3d06a..10a140dbff8c 100644 --- a/components/notification/__tests__/hooks.test.tsx +++ b/components/notification/__tests__/hooks.test.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/jsx-no-useless-fragment */ import React from 'react'; import { render, fireEvent, pureRender } from '../../../tests/utils'; import notification from '..'; @@ -119,7 +118,7 @@ describe('notification.hooks', () => { }); }, []); - return <>{holder}; + return holder; }; render(); @@ -130,7 +129,7 @@ describe('notification.hooks', () => { it('warning if user call update in render', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - const Demo: React.FC = () => { + const Demo = () => { const [api, holder] = notification.useNotification(); const calledRef = React.useRef(false); @@ -142,7 +141,7 @@ describe('notification.hooks', () => { calledRef.current = true; } - return <>{holder}; + return holder; }; render(); diff --git a/components/notification/useNotification.tsx b/components/notification/useNotification.tsx index 7bfa7d3896dd..53ebb51e0bf5 100644 --- a/components/notification/useNotification.tsx +++ b/components/notification/useNotification.tsx @@ -84,7 +84,7 @@ const Holder = React.forwardRef((props, ref) => { // ============================================================================== export function useInternalNotification( notificationConfig?: HolderProps, -): readonly [NotificationInstance, React.ReactNode] { +): readonly [NotificationInstance, React.ReactElement] { const holderRef = React.useRef(null); // ================================ API ================================