UNPKG

1.87 kBTypeScriptView Raw
1import { StateManagerProps } from './useStateManager';
2import { GroupBase, OptionsOrGroups } from './types';
3declare type AsyncManagedPropKeys = 'options' | 'isLoading' | 'onInputChange' | 'filterOption';
4export interface AsyncAdditionalProps<Option, Group extends GroupBase<Option>> {
5 /**
6 * The default set of options to show before the user starts searching. When
7 * set to `true`, the results for loadOptions('') will be autoloaded.
8 */
9 defaultOptions?: OptionsOrGroups<Option, Group> | boolean;
10 /**
11 * If cacheOptions is truthy, then the loaded data will be cached. The cache
12 * will remain until `cacheOptions` changes value.
13 */
14 cacheOptions?: any;
15 /**
16 * Function that returns a promise, which is the set of options to be used
17 * once the promise resolves.
18 */
19 loadOptions?: (inputValue: string, callback: (options: OptionsOrGroups<Option, Group>) => void) => Promise<OptionsOrGroups<Option, Group>> | void;
20 /**
21 * Will cause the select to be displayed in the loading state, even if the
22 * Async select is not currently waiting for loadOptions to resolve
23 */
24 isLoading?: boolean;
25}
26export declare type AsyncProps<Option, IsMulti extends boolean, Group extends GroupBase<Option>> = StateManagerProps<Option, IsMulti, Group> & AsyncAdditionalProps<Option, Group>;
27export default function useAsync<Option, IsMulti extends boolean, Group extends GroupBase<Option>, AdditionalProps>({ defaultOptions: propsDefaultOptions, cacheOptions, loadOptions: propsLoadOptions, options: propsOptions, isLoading: propsIsLoading, onInputChange: propsOnInputChange, filterOption, ...restSelectProps }: AsyncProps<Option, IsMulti, Group> & AdditionalProps): StateManagerProps<Option, IsMulti, Group> & Omit<AdditionalProps, keyof AsyncAdditionalProps<Option, Group> | AsyncManagedPropKeys>;
28export {};