@@ -3,8 +3,10 @@ import Autosuggest from "react-autosuggest";
3
3
import config from "../../config" ;
4
4
import api from "../../services/api" ;
5
5
import style from "./style.module.scss" ;
6
+ import _ from "lodash" ;
6
7
7
8
const NO_RESULTS_FOUND = "no results found" ;
9
+ const DELAY_SEARCH = 300 ;
8
10
9
11
/**
10
12
* Decides what is displayed after the user selects a suggestion
@@ -102,6 +104,7 @@ export default function SuggestionBox({
102
104
const onSuggestionsFetchRequested = async ( { value } ) => {
103
105
if ( purpose === "skills" ) {
104
106
let data = await getSkillsSuggestions ( apiClient , value ) ;
107
+
105
108
if ( data . length < 1 ) data = [ { name : NO_RESULTS_FOUND } ] ;
106
109
setSuggestions ( data ) ;
107
110
} else {
@@ -115,6 +118,11 @@ export default function SuggestionBox({
115
118
}
116
119
} ;
117
120
121
+ const onSuggestionsFetchRequestedDebounce = React . useCallback (
122
+ _ . debounce ( onSuggestionsFetchRequested , DELAY_SEARCH ) ,
123
+ [ ]
124
+ ) ;
125
+
118
126
const onSuggestionsClearRequested = ( ) => setSuggestions ( [ ] ) ;
119
127
120
128
const onSuggestionSelected = ( event , { suggestion } ) => {
@@ -140,7 +148,7 @@ export default function SuggestionBox({
140
148
return (
141
149
< Autosuggest
142
150
suggestions = { suggestions }
143
- onSuggestionsFetchRequested = { onSuggestionsFetchRequested }
151
+ onSuggestionsFetchRequested = { onSuggestionsFetchRequestedDebounce }
144
152
onSuggestionsClearRequested = { onSuggestionsClearRequested }
145
153
onSuggestionSelected = { onSuggestionSelected }
146
154
getSuggestionValue = { getSuggestionValue }
0 commit comments