Skip to content

Commit 07c4c5a

Browse files
author
刘欢
committed
feat: change useSearchConfig
1 parent ec8ee9a commit 07c4c5a

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/hooks/useSearchConfig.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,25 @@ const legacySearchProps = [
1111
'tokenSeparators',
1212
];
1313
// Convert `showSearch` to unique config
14-
export default function useSearchConfig(showSearch, props) {
15-
return React.useMemo<[boolean, SearchConfig<DefaultOptionType>]>(() => {
14+
export default function useSearchConfig(
15+
showSearch: boolean | SearchConfig<DefaultOptionType> | undefined,
16+
props: any,
17+
) {
18+
const {
19+
filterOption,
20+
searchValue,
21+
optionFilterProp,
22+
optionLabelProp,
23+
filterSort,
24+
onSearch,
25+
autoClearSearchValue,
26+
tokenSeparators,
27+
} = props || {};
28+
return React.useMemo<[boolean | undefined, SearchConfig<DefaultOptionType>]>(() => {
1629
const legacyShowSearch: SearchConfig<DefaultOptionType> = {};
17-
legacySearchProps.forEach((propsName) => {
18-
legacyShowSearch[propsName] = props?.[propsName];
30+
legacySearchProps.forEach((name) => {
31+
const val = props?.[name];
32+
if (val !== undefined) legacyShowSearch[name] = val;
1933
});
2034
const searchConfig: SearchConfig<DefaultOptionType> =
2135
typeof showSearch === 'object' ? showSearch : legacyShowSearch;
@@ -28,13 +42,13 @@ export default function useSearchConfig(showSearch, props) {
2842
return [true, searchConfig];
2943
}, [
3044
showSearch,
31-
props?.filterOption,
32-
props?.searchValue,
33-
props?.optionFilterProp,
34-
props?.optionLabelProp,
35-
props?.filterSort,
36-
props?.onSearch,
37-
props?.autoClearSearchValue,
38-
props?.tokenSeparators,
45+
filterOption,
46+
searchValue,
47+
optionFilterProp,
48+
optionLabelProp,
49+
filterSort,
50+
onSearch,
51+
autoClearSearchValue,
52+
tokenSeparators,
3953
]);
4054
}

0 commit comments

Comments
 (0)