import { UseAsyncListingProps, UseAsyncListingReturn, UseAsyncValueReturn } from '@prestojs/util'; import { AsyncChoicesInterface } from './fields/AsyncChoices'; /** * @expandproperties */ export declare type UseAsyncChoicesProps = Pick, 'accumulatePages' | 'query' | 'trigger'> & { /** * The async choices instance. */ asyncChoices: AsyncChoicesInterface; /** * The currently selected choice(s) - if any * * When specified the corresponding label(s) will be resolved * automatically. */ value?: ValueT[] | ValueT | null; /** * If provided this function will be called whenever a value is successfully * resolved using `asyncChoices.retrieve`. */ onRetrieveSuccess?: (response: ItemT[] | ItemT) => void; /** * If provided this function will be called whenever `asyncChoices.retrieve` errors * * You can use this to do things like unset a value if it no longer exists. */ onRetrieveError?: (error: Error) => void; /** * Any extra options to pass through to [list](doc:AsyncChoicesInterface#method-list) * * These will be available in both [useListProps](doc:AsyncChoicesInterface#method-list) and [list](doc:AsyncChoicesInterface#method-useListProps) under the `listOptions` * key */ listOptions?: Record; /** * Any extra options to pass through to [retrieve](doc:AsyncChoicesInterface#method-retrieve) * * These will be available in both [useRetrieveProps](doc:AsyncChoicesInterface#method-retrieve) and [retrieve](doc:AsyncChoicesInterface#method-useRetrieveProps) under the `retrieveOptions` * key */ retrieveOptions?: Record; }; /** * @expandproperties */ export declare type UseAsyncChoicesReturn = { /** * See [useAsyncListing](doc:useAsyncListing#return-type) */ list: UseAsyncListingReturn; /** * See [useAsyncValue](doc:useAsyncValue#return-type) */ selected: UseAsyncValueReturn; /** * See [getChoices](doc:AsyncChoicesInterface#method-getChoices) */ choices: ReturnType['getChoices']>; }; /** * Hook that makes it easy to use an [AsyncChoices](doc:AsyncChoicesInterface) definition. * * This hook does the following: * * 1) Calls [useListProps](doc:AsyncChoicesInterface#method-useListProps) to get any dependencies for [list](doc:AsyncChoicesInterface#method-list) * * 2) Calls [list](doc:AsyncChoicesInterface#method-list) and passes through the dependencies and a `query` object representing any query parameters for the async call * * 3) Calls [useRetrieveProps](doc:AsyncChoicesInterface#method-useRetrieveProps) to get any dependencies for [retrieve](doc:AsyncChoicesInterface#method-retrieve) * * 4) If there is a current `value` [retrieve](doc:AsyncChoicesInterface#method-retrieve) is called and is passed the dependencies returned above * * 5) An object is returned with the available choices in `choices`, the result of 2 in `list` and result of 4 in `selected` * * @extractdocs * @menugroup Async Choices */ export default function useAsyncChoices(props: UseAsyncChoicesProps): UseAsyncChoicesReturn;