You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
547 B
18 lines
547 B
import React from 'react';
|
|
/**
|
|
* Return cached Key Value map with DataNode.
|
|
* Only re-calculate when `flattenOptions` changed.
|
|
*/
|
|
|
|
export default function useKeyValueMap(flattenOptions) {
|
|
return React.useMemo(function () {
|
|
var cacheKeyMap = new Map();
|
|
var cacheValueMap = new Map(); // Cache options by key
|
|
|
|
flattenOptions.forEach(function (dataNode) {
|
|
cacheKeyMap.set(dataNode.key, dataNode);
|
|
cacheValueMap.set(dataNode.data.value, dataNode);
|
|
});
|
|
return [cacheKeyMap, cacheValueMap];
|
|
}, [flattenOptions]);
|
|
} |