1
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
import * as React from 'react';
|
||||
import useEntities from "./useEntities";
|
||||
export default function useOptions(mergedFieldNames, options) {
|
||||
const mergedOptions = React.useMemo(() => options || [], [options]);
|
||||
|
||||
// Only used in multiple mode, this fn will not call in single mode
|
||||
const getPathKeyEntities = useEntities(mergedOptions, mergedFieldNames);
|
||||
|
||||
/** Convert path key back to value format */
|
||||
const getValueByKeyPath = React.useCallback(pathKeys => {
|
||||
const keyPathEntities = getPathKeyEntities();
|
||||
return pathKeys.map(pathKey => {
|
||||
const {
|
||||
nodes
|
||||
} = keyPathEntities[pathKey];
|
||||
return nodes.map(node => node[mergedFieldNames.value]);
|
||||
});
|
||||
}, [getPathKeyEntities, mergedFieldNames]);
|
||||
return [mergedOptions, getPathKeyEntities, getValueByKeyPath];
|
||||
}
|
||||
Reference in New Issue
Block a user