Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Fix: Debounce input events on search in home page #1532

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Bloodhound from 'corejs-typeahead';
import React, {useState, useCallback, useRef} from 'react';
import * as Icon from 'react-feather';
import {Link} from 'react-router-dom';
import {useDebounce} from 'react-use';

const engine = new Bloodhound({
initialize: true,
Expand Down Expand Up @@ -106,6 +107,18 @@ function Search(props) {
essentialsEngine.search(searchInput, essentialsSync, essentialsAsync);
}, []);

useDebounce(
() => {
if (searchValue) {
handleSearch(searchValue.toLowerCase());
} else {
setResults([]);
}
},
800,
[searchValue]
);

function setNativeValue(element, value) {
const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set;
const prototype = Object.getPrototypeOf(element);
Expand Down Expand Up @@ -138,7 +151,6 @@ function Search(props) {
}}
onChange={(event) => {
setSearchValue(event.target.value);
handleSearch(event.target.value.toLowerCase());
}}
/>

Expand Down