From 17af68da016d76c59c30f6e05b5e9d7e2c067e9c Mon Sep 17 00:00:00 2001 From: zombiej Date: Thu, 7 Apr 2022 14:21:57 +0800 Subject: [PATCH 1/3] 5.19.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d7f66935..f8c8af79 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-util", - "version": "5.19.3", + "version": "5.19.4", "description": "Common Utils For React Component", "keywords": [ "react", From 5cd69f0fbd32bea190ea6070f70597d3b64ac745 Mon Sep 17 00:00:00 2001 From: zombiej Date: Thu, 7 Apr 2022 15:00:37 +0800 Subject: [PATCH 2/3] fix: React 18 useState --- src/hooks/useState.ts | 11 ++++++----- tests/hooks.test.js | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/hooks/useState.ts b/src/hooks/useState.ts index d08cdbef..7cbfa8eb 100644 --- a/src/hooks/useState.ts +++ b/src/hooks/useState.ts @@ -22,12 +22,13 @@ export default function useState( const destroyRef = React.useRef(false); const [value, setValue] = React.useState(defaultValue); - React.useEffect( - () => () => { + React.useEffect(() => { + destroyRef.current = false; + + return () => { destroyRef.current = true; - }, - [], - ); + }; + }, []); function safeSetState(updater: Updater, ignoreDestroy?: boolean) { if (ignoreDestroy && destroyRef.current) { diff --git a/tests/hooks.test.js b/tests/hooks.test.js index 0a769388..caa4f773 100644 --- a/tests/hooks.test.js +++ b/tests/hooks.test.js @@ -137,10 +137,28 @@ describe('hooks', () => { [], ); - return null; + return ( + + ); }; - const { unmount } = render(); + const { container, unmount } = render( + + + , + ); + expect(container.querySelector('button').textContent).toEqual('0'); + + // Update Value + fireEvent.click(container.querySelector('button')); + expect(container.querySelector('button').textContent).toEqual('93'); + unmount(); setTimeout(() => { From 3bc83be5013aec8f7273a6cd582df7566b71e017 Mon Sep 17 00:00:00 2001 From: zombiej Date: Thu, 7 Apr 2022 15:02:02 +0800 Subject: [PATCH 3/3] chore: cleanup --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f8c8af79..d7f66935 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rc-util", - "version": "5.19.4", + "version": "5.19.3", "description": "Common Utils For React Component", "keywords": [ "react",