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.
31 lines
812 B
31 lines
812 B
"use strict";
|
|
|
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = useCacheOptions;
|
|
|
|
var React = _interopRequireWildcard(require("react"));
|
|
|
|
function useCacheOptions(values, options) {
|
|
var prevOptionMapRef = React.useRef(null);
|
|
var optionMap = React.useMemo(function () {
|
|
var map = new Map();
|
|
options.forEach(function (item) {
|
|
var value = item.data.value;
|
|
map.set(value, item);
|
|
});
|
|
return map;
|
|
}, [values, options]);
|
|
prevOptionMapRef.current = optionMap;
|
|
|
|
var getValueOption = function getValueOption(vals) {
|
|
return vals.map(function (value) {
|
|
return prevOptionMapRef.current.get(value);
|
|
}).filter(Boolean);
|
|
};
|
|
|
|
return getValueOption;
|
|
} |