Skip to content

Commit c127aad

Browse files
EmilyyyLiu刘欢
andauthored
refactor: Upgrade utils and replace useMergedState (#161)
Co-authored-by: 刘欢 <lh01217311@antgroup.com>
1 parent 86b7162 commit c127aad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"dependencies": {
4646
"classnames": "^2.2.1",
47-
"@rc-component/util": "^1.2.0"
47+
"@rc-component/util": "^1.3.0"
4848
},
4949
"devDependencies": {
5050
"@rc-component/father-plugin": "^2.0.0",

src/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import classNames from 'classnames';
3-
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
3+
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
44
import KeyCode from '@rc-component/util/lib/KeyCode';
55

66
export type SwitchChangeEventHandler = (
@@ -49,10 +49,10 @@ const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
4949
},
5050
ref,
5151
) => {
52-
const [innerChecked, setInnerChecked] = useMergedState<boolean>(false, {
53-
value: checked,
54-
defaultValue: defaultChecked,
55-
});
52+
const [innerChecked, setInnerChecked] = useControlledState<boolean>(
53+
defaultChecked ?? false,
54+
checked,
55+
);
5656

5757
function triggerChange(
5858
newChecked: boolean,

0 commit comments

Comments
 (0)