11import debounce from 'lodash.debounce' ;
2- import { ChangeEvent , ReactNode , useCallback , useEffect , useRef } from 'react' ;
2+ import { ChangeEvent , useCallback , useEffect , useRef } from 'react' ;
33import useForceUpdate from '@restart/hooks/useForceUpdate' ;
44import usePrevious from '@restart/hooks/usePrevious' ;
55
66import { isFunction } from '../utils' ;
77
8- import { TypeaheadComponentProps } from '../components/Typeahead' ;
9- import type { Option } from '../types' ;
8+ import type { Option , TypeaheadProps } from '../types' ;
109
11- export interface UseAsyncProps extends TypeaheadComponentProps {
10+ export interface UseAsyncProps extends TypeaheadProps {
1211 /**
1312 * Delay, in milliseconds, before performing search.
1413 */
@@ -22,14 +21,6 @@ export interface UseAsyncProps extends TypeaheadComponentProps {
2221 * Callback to perform when the search is executed.
2322 */
2423 onSearch : ( query : string ) => void ;
25- /**
26- * Message displayed in the menu when there is no user input.
27- */
28- promptText ?: ReactNode ;
29- /**
30- * Message displayed in the menu while the request is pending.
31- */
32- searchText ?: ReactNode ;
3324 /**
3425 * Whether or not the component should cache query results.
3526 */
@@ -54,14 +45,11 @@ function useAsync(props: UseAsyncProps) {
5445 const {
5546 allowNew,
5647 delay = 200 ,
57- emptyLabel,
5848 isLoading,
5949 minLength = 2 ,
6050 onInputChange,
6151 onSearch,
6252 options = [ ] ,
63- promptText = 'Type to search...' ,
64- searchText = 'Searching...' ,
6553 useCache = true ,
6654 ...otherProps
6755 } = props ;
@@ -114,18 +102,6 @@ function useAsync(props: UseAsyncProps) {
114102 }
115103 } ) ;
116104
117- const getEmptyLabel = ( ) => {
118- if ( ! queryRef . current . length ) {
119- return promptText ;
120- }
121-
122- if ( isLoading ) {
123- return searchText ;
124- }
125-
126- return emptyLabel ;
127- } ;
128-
129105 const handleInputChange = useCallback (
130106 ( query : string , e : ChangeEvent < HTMLInputElement > ) => {
131107 onInputChange && onInputChange ( query , e ) ;
@@ -142,11 +118,11 @@ function useAsync(props: UseAsyncProps) {
142118 ...otherProps ,
143119 // Disable custom selections during a search if `allowNew` isn't a function.
144120 allowNew : isFunction ( allowNew ) ? allowNew : allowNew && ! isLoading ,
145- emptyLabel : getEmptyLabel ( ) ,
146121 isLoading,
147122 minLength,
148123 onInputChange : handleInputChange ,
149124 options : useCache && cachedQuery ? cachedQuery : options ,
125+ query : queryRef . current ,
150126 } ;
151127}
152128
0 commit comments