Skip to content

Commit 3cc9d0f

Browse files
EmilyyyLiu刘欢
andauthored
refactor: Upgrade utils and replace useMergedState (#1162)
* refactor: Upgrade utils and replace useMergedState * feat: set default value "" --------- Co-authored-by: 刘欢 <[email protected]>
1 parent 143e4d2 commit 3cc9d0f

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"dependencies": {
5252
"@rc-component/trigger": "^3.0.0",
5353
"@rc-component/motion": "^1.1.4",
54-
"@rc-component/util": "^1.2.1",
54+
"@rc-component/util": "^1.3.0",
5555
"classnames": "2.x",
5656
"rc-overflow": "^1.4.0",
5757
"rc-virtual-list": "^3.5.2"

src/BaseSelect/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AlignType, BuildInPlacements } from '@rc-component/trigger/lib/interface';
22
import cls from 'classnames';
33
import useLayoutEffect from '@rc-component/util/lib/hooks/useLayoutEffect';
4-
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
4+
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
55
import isMobile from '@rc-component/util/lib/isMobile';
66
import { useComposeRef } from '@rc-component/util/lib/ref';
77
import { getDOM } from '@rc-component/util/lib/Dom/findDOMNode';
@@ -383,10 +383,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
383383
setRendered(true);
384384
}, []);
385385

386-
const [innerOpen, setInnerOpen] = useMergedState<boolean>(false, {
387-
defaultValue: defaultOpen,
388-
value: open,
389-
});
386+
const [innerOpen, setInnerOpen] = useControlledState<boolean>(defaultOpen || false, open);
390387

391388
let mergedOpen = rendered ? innerOpen : false;
392389

src/Select.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* - `combobox` mode not support `optionLabelProp`
3030
*/
3131

32-
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
32+
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
3333
import warning from '@rc-component/util/lib/warning';
3434
import * as React from 'react';
3535
import type {
@@ -272,10 +272,8 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
272272
);
273273

274274
// =========================== Search ===========================
275-
const [mergedSearchValue, setSearchValue] = useMergedState('', {
276-
value: searchValue,
277-
postState: (search) => search || '',
278-
});
275+
const [internalSearchValue, setSearchValue] = useControlledState('', searchValue);
276+
const mergedSearchValue = internalSearchValue || '';
279277

280278
// =========================== Option ===========================
281279
const parsedOptions = useOptions(
@@ -343,9 +341,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
343341
);
344342

345343
// =========================== Values ===========================
346-
const [internalValue, setInternalValue] = useMergedState(defaultValue, {
347-
value,
348-
});
344+
const [internalValue, setInternalValue] = useControlledState(defaultValue, value);
349345

350346
// Merged value with LabelValueType
351347
const rawLabeledValues = React.useMemo(() => {

0 commit comments

Comments
 (0)