Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 238620d

Browse files
committedJul 26, 2020
Merge branch 'issue-552' into develop
2 parents 7c29598 + 5c86ae1 commit 238620d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎client/src/components/SuggestionBox/index.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import Autosuggest from "react-autosuggest";
33
import config from "../../config";
44
import api from "../../services/api";
55
import style from "./style.module.scss";
6+
import _ from "lodash";
67

78
const NO_RESULTS_FOUND = "no results found";
9+
const DELAY_SEARCH = 300;
810

911
/**
1012
* Decides what is displayed after the user selects a suggestion
@@ -102,6 +104,7 @@ export default function SuggestionBox({
102104
const onSuggestionsFetchRequested = async ({ value }) => {
103105
if (purpose === "skills") {
104106
let data = await getSkillsSuggestions(apiClient, value);
107+
105108
if (data.length < 1) data = [{ name: NO_RESULTS_FOUND }];
106109
setSuggestions(data);
107110
} else {
@@ -115,6 +118,11 @@ export default function SuggestionBox({
115118
}
116119
};
117120

121+
const onSuggestionsFetchRequestedDebounce = React.useCallback(
122+
_.debounce(onSuggestionsFetchRequested, DELAY_SEARCH),
123+
[]
124+
);
125+
118126
const onSuggestionsClearRequested = () => setSuggestions([]);
119127

120128
const onSuggestionSelected = (event, { suggestion }) => {
@@ -140,7 +148,7 @@ export default function SuggestionBox({
140148
return (
141149
<Autosuggest
142150
suggestions={suggestions}
143-
onSuggestionsFetchRequested={onSuggestionsFetchRequested}
151+
onSuggestionsFetchRequested={onSuggestionsFetchRequestedDebounce}
144152
onSuggestionsClearRequested={onSuggestionsClearRequested}
145153
onSuggestionSelected={onSuggestionSelected}
146154
getSuggestionValue={getSuggestionValue}

0 commit comments

Comments
 (0)
This repository has been archived.