Skip to content

Commit

Permalink
type: add type (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan committed Dec 27, 2023
1 parent 424bcfd commit 56fd0d9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/hooks/useOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { convertChildrenToData } from '../utils/legacyUtil';
* Parse `children` to `options` if `options` is not provided.
* Then flatten the `options`.
*/
export default function useOptions<OptionType>(
const useOptions = <OptionType>(
options: OptionType[],
children: React.ReactNode,
fieldNames: FieldNames,
optionFilterProp: string,
optionLabelProp: string,
) {
) => {
return React.useMemo(() => {
let mergedOptions = options;
const childrenAsData = !options;
Expand All @@ -24,13 +24,17 @@ export default function useOptions<OptionType>(
const valueOptions = new Map<RawValueType, OptionType>();
const labelOptions = new Map<React.ReactNode, OptionType>();

const setLabelOptions = (labelOptionsMap, option, key) => {
const setLabelOptions = (
labelOptionsMap: Map<React.ReactNode, OptionType>,
option: OptionType,
key: string | number,
) => {
if (key && typeof key === 'string') {
labelOptionsMap.set(option[key], option);
}
};

function dig(optionList: OptionType[], isChildren = false) {
const dig = (optionList: OptionType[], isChildren = false) => {
// for loop to speed up collection speed
for (let i = 0; i < optionList.length; i += 1) {
const option = optionList[i];
Expand All @@ -44,7 +48,8 @@ export default function useOptions<OptionType>(
dig(option[fieldNames.options], true);
}
}
}
};

dig(mergedOptions);

return {
Expand All @@ -53,4 +58,6 @@ export default function useOptions<OptionType>(
labelOptions,
};
}, [options, children, fieldNames, optionFilterProp, optionLabelProp]);
}
};

export default useOptions;

1 comment on commit 56fd0d9

@vercel
Copy link

@vercel vercel bot commented on 56fd0d9 Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

select – ./

select-git-master-react-component.vercel.app
select.vercel.app
select-react-component.vercel.app

Please sign in to comment.