From 5787f0b97b9b5d4ab193233e4445436a090dc81a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=AC=A2?= Date: Fri, 12 Sep 2025 13:52:26 +0800 Subject: [PATCH] refactor: Upgrade utils and replace useMergedState --- package.json | 2 +- src/index.tsx | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6349924..c29fb45 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ }, "dependencies": { "classnames": "^2.2.1", - "@rc-component/util": "^1.2.0" + "@rc-component/util": "^1.3.0" }, "devDependencies": { "@rc-component/father-plugin": "^2.0.0", diff --git a/src/index.tsx b/src/index.tsx index b4ce9b6..ae9a0e9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import classNames from 'classnames'; -import useMergedState from '@rc-component/util/lib/hooks/useMergedState'; +import useControlledState from '@rc-component/util/lib/hooks/useControlledState'; import KeyCode from '@rc-component/util/lib/KeyCode'; export type SwitchChangeEventHandler = ( @@ -49,10 +49,10 @@ const Switch = React.forwardRef( }, ref, ) => { - const [innerChecked, setInnerChecked] = useMergedState(false, { - value: checked, - defaultValue: defaultChecked, - }); + const [innerChecked, setInnerChecked] = useControlledState( + defaultChecked ?? false, + checked, + ); function triggerChange( newChecked: boolean,