@@ -3,42 +3,36 @@ import type { RawValueType } from '../BaseSelect';
33import type { DefaultOptionType , LabelInValueType } from '../Select' ;
44
55/**
6- * Cache `value ` related LabeledValue & options.
6+ * Cache `options ` related LabeledValue & options.
77 */
88export default (
99 labeledValues : LabelInValueType [ ] ,
1010 valueOptions : Map < RawValueType , DefaultOptionType > ,
1111) : [ LabelInValueType [ ] , ( val : RawValueType ) => DefaultOptionType ] => {
1212 const cacheRef = React . useRef ( {
13- values : new Map < RawValueType , LabelInValueType > ( ) ,
1413 options : new Map < RawValueType , DefaultOptionType > ( ) ,
1514 } ) ;
1615
1716 const filledLabeledValues = React . useMemo ( ( ) => {
18- const { values : prevValueCache , options : prevOptionCache } = cacheRef . current ;
19-
17+ const { options : prevOptionCache } = cacheRef . current ;
2018 // Fill label by cache
2119 const patchedValues = labeledValues . map ( ( item ) => {
2220 if ( item . label === undefined ) {
2321 return {
2422 ...item ,
25- label : prevValueCache . get ( item . value ) ?. label ,
23+ label : prevOptionCache . get ( item . value ) ?. label ,
2624 } ;
2725 }
2826
2927 return item ;
3028 } ) ;
3129
32- // Refresh cache
33- const valueCache = new Map < RawValueType , LabelInValueType > ( ) ;
3430 const optionCache = new Map < RawValueType , DefaultOptionType > ( ) ;
3531
3632 patchedValues . forEach ( ( item ) => {
37- valueCache . set ( item . value , item ) ;
3833 optionCache . set ( item . value , valueOptions . get ( item . value ) || prevOptionCache . get ( item . value ) ) ;
3934 } ) ;
4035
41- cacheRef . current . values = valueCache ;
4236 cacheRef . current . options = optionCache ;
4337
4438 return patchedValues ;
0 commit comments