From 489feee5934e6864cebd48752deb95ffa877aa5b Mon Sep 17 00:00:00 2001 From: Hope Tambala Date: Sat, 27 Mar 2021 09:39:18 -0400 Subject: [PATCH] fix: create timer for when the search calls from the database --- components/ResidentIdSearchbar/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/ResidentIdSearchbar/index.js b/components/ResidentIdSearchbar/index.js index 09e0849f6..5c34d77ee 100644 --- a/components/ResidentIdSearchbar/index.js +++ b/components/ResidentIdSearchbar/index.js @@ -15,6 +15,7 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) = const [residentsData, setResidentsData] = useState([]); const [loading, setLoading] = useState(false); const [offline, setOffline] = useState(true); + const [searchTimeout, setSearchTimeout] = useState(null); useEffect(() => { checkOnlineStatus().then(async (connected) => { @@ -92,8 +93,13 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) = ); const onChangeSearch = (input) => { - fetchData(); + clearTimeout(searchTimeout); + setQuery(input); + + setSearchTimeout(setTimeout(() => { + fetchData(); + }, 1000)); }; const onSelectSurveyee = (listItem) => {