Skip to content

Commit db53009

Browse files
EmilyyyLiu刘欢
andauthored
refactor: Upgrade utils and replace useMergedState (#648)
Co-authored-by: 刘欢 <[email protected]>
1 parent 23f4ebf commit db53009

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"classnames": "2.x",
4848
"@rc-component/select": "~1.1.0",
4949
"@rc-component/tree": "~1.0.1",
50-
"@rc-component/util": "^1.2.1"
50+
"@rc-component/util": "^1.3.0"
5151
},
5252
"devDependencies": {
5353
"@rc-component/father-plugin": "^2.0.2",

src/TreeSelect.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import useId from '@rc-component/util/lib/hooks/useId';
44
import type { IconType } from '@rc-component/tree/lib/interface';
55
import type { ExpandAction } from '@rc-component/tree/lib/Tree';
66
import { conductCheck } from '@rc-component/tree/lib/utils/conductUtil';
7-
import useMergedState from '@rc-component/util/lib/hooks/useMergedState';
7+
import useControlledState from '@rc-component/util/lib/hooks/useControlledState';
88
import * as React from 'react';
99
import useCache from './hooks/useCache';
1010
import useCheckedKeys from './hooks/useCheckedKeys';
@@ -224,7 +224,7 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
224224
treeNodeFilterProp = 'value',
225225
} = searchConfig;
226226

227-
const [internalValue, setInternalValue] = useMergedState(defaultValue, { value });
227+
const [internalValue, setInternalValue] = useControlledState(defaultValue, value);
228228

229229
// `multiple` && `!treeCheckable` should be show all
230230
const mergedShowCheckedStrategy = React.useMemo(() => {
@@ -249,10 +249,8 @@ const TreeSelect = React.forwardRef<BaseSelectRef, TreeSelectProps>((props, ref)
249249
);
250250

251251
// =========================== Search ===========================
252-
const [mergedSearchValue, setSearchValue] = useMergedState('', {
253-
value: searchValue,
254-
postState: search => search || '',
255-
});
252+
const [internalSearchValue, setSearchValue] = useControlledState('', searchValue);
253+
const mergedSearchValue = internalSearchValue || '';
256254

257255
const onInternalSearch = searchText => {
258256
setSearchValue(searchText);

0 commit comments

Comments
 (0)