@@ -6,13 +6,13 @@ import { convertChildrenToData } from '../utils/legacyUtil';
6
6
* Parse `children` to `options` if `options` is not provided.
7
7
* Then flatten the `options`.
8
8
*/
9
- export default function useOptions < OptionType > (
9
+ const useOptions = < OptionType > (
10
10
options : OptionType [ ] ,
11
11
children : React . ReactNode ,
12
12
fieldNames : FieldNames ,
13
13
optionFilterProp : string ,
14
14
optionLabelProp : string ,
15
- ) {
15
+ ) => {
16
16
return React . useMemo ( ( ) => {
17
17
let mergedOptions = options ;
18
18
const childrenAsData = ! options ;
@@ -24,13 +24,17 @@ export default function useOptions<OptionType>(
24
24
const valueOptions = new Map < RawValueType , OptionType > ( ) ;
25
25
const labelOptions = new Map < React . ReactNode , OptionType > ( ) ;
26
26
27
- const setLabelOptions = ( labelOptionsMap , option , key ) => {
27
+ const setLabelOptions = (
28
+ labelOptionsMap : Map < React . ReactNode , OptionType > ,
29
+ option : OptionType ,
30
+ key : string | number ,
31
+ ) => {
28
32
if ( key && typeof key === 'string' ) {
29
33
labelOptionsMap . set ( option [ key ] , option ) ;
30
34
}
31
35
} ;
32
36
33
- function dig ( optionList : OptionType [ ] , isChildren = false ) {
37
+ const dig = ( optionList : OptionType [ ] , isChildren = false ) => {
34
38
// for loop to speed up collection speed
35
39
for ( let i = 0 ; i < optionList . length ; i += 1 ) {
36
40
const option = optionList [ i ] ;
@@ -44,7 +48,8 @@ export default function useOptions<OptionType>(
44
48
dig ( option [ fieldNames . options ] , true ) ;
45
49
}
46
50
}
47
- }
51
+ } ;
52
+
48
53
dig ( mergedOptions ) ;
49
54
50
55
return {
@@ -53,4 +58,6 @@ export default function useOptions<OptionType>(
53
58
labelOptions,
54
59
} ;
55
60
} , [ options , children , fieldNames , optionFilterProp , optionLabelProp ] ) ;
56
- }
61
+ } ;
62
+
63
+ export default useOptions ;
0 commit comments