Skip to content

Commit

Permalink
fix: create timer for when the search calls from the database
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Mar 27, 2021
1 parent 8c52608 commit 489feee
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion components/ResidentIdSearchbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -92,8 +93,13 @@ const ResidentIdSearchbar = ({ surveyee, setSurveyee, surveyingOrganization }) =
);

const onChangeSearch = (input) => {
fetchData();
clearTimeout(searchTimeout);

setQuery(input);

setSearchTimeout(setTimeout(() => {
fetchData();
}, 1000));
};

const onSelectSurveyee = (listItem) => {
Expand Down

0 comments on commit 489feee

Please sign in to comment.