@@ -3,42 +3,36 @@ import type { RawValueType } from '../BaseSelect';
3
3
import type { DefaultOptionType , LabelInValueType } from '../Select' ;
4
4
5
5
/**
6
- * Cache `value ` related LabeledValue & options.
6
+ * Cache `options ` related LabeledValue & options.
7
7
*/
8
8
export default (
9
9
labeledValues : LabelInValueType [ ] ,
10
10
valueOptions : Map < RawValueType , DefaultOptionType > ,
11
11
) : [ LabelInValueType [ ] , ( val : RawValueType ) => DefaultOptionType ] => {
12
12
const cacheRef = React . useRef ( {
13
- values : new Map < RawValueType , LabelInValueType > ( ) ,
14
13
options : new Map < RawValueType , DefaultOptionType > ( ) ,
15
14
} ) ;
16
15
17
16
const filledLabeledValues = React . useMemo ( ( ) => {
18
- const { values : prevValueCache , options : prevOptionCache } = cacheRef . current ;
19
-
17
+ const { options : prevOptionCache } = cacheRef . current ;
20
18
// Fill label by cache
21
19
const patchedValues = labeledValues . map ( ( item ) => {
22
20
if ( item . label === undefined ) {
23
21
return {
24
22
...item ,
25
- label : prevValueCache . get ( item . value ) ?. label ,
23
+ label : prevOptionCache . get ( item . value ) ?. label ,
26
24
} ;
27
25
}
28
26
29
27
return item ;
30
28
} ) ;
31
29
32
- // Refresh cache
33
- const valueCache = new Map < RawValueType , LabelInValueType > ( ) ;
34
30
const optionCache = new Map < RawValueType , DefaultOptionType > ( ) ;
35
31
36
32
patchedValues . forEach ( ( item ) => {
37
- valueCache . set ( item . value , item ) ;
38
33
optionCache . set ( item . value , valueOptions . get ( item . value ) || prevOptionCache . get ( item . value ) ) ;
39
34
} ) ;
40
35
41
- cacheRef . current . values = valueCache ;
42
36
cacheRef . current . options = optionCache ;
43
37
44
38
return patchedValues ;
0 commit comments