on master help sign in
Merge pull request #1417 from urbit/mp/debounce-search

search: debounce input

commitbb0e47949a6734fbf8868942f796485b2e010950 authormatildepark <matilde.park@urbit.org> dateSat 23 Apr 2022, 00:37 (5 years ago) parent2f5f81a3b8fc3c
3 files changed+15−2
components/Search.js+3−2 package-lock.json+11 package.json+1
components/Search.js+3−2
@@ -1,6 +1,7 @@
11import { Component, createRef } from "react";
22import { glossary } from "../lib/glossary";
33import { withRouter } from "next/router";
4+import debounce from "lodash.debounce";
45import Downshift from "downshift";
56
67class Search extends Component {
@@ -38,7 +39,7 @@ class Search extends Component {
3839 this.props.closeSearch();
3940 }
4041
41− onInputValueChange(query) {
42+ onInputValueChange = debounce((query) => {
4243 if (query.length) {
4344 fetch(this.searchEndpoint(query))
4445 .then((res) => res.json())
@@ -61,7 +62,7 @@ class Search extends Component {
6162 } else {
6263 this.setState({ results: [] });
6364 }
64− }
65+ }, 250);
6566
6667 render() {
6768 const { state, props } = this;
package-lock.json+11
@@ -19,6 +19,7 @@
1919 "fuzzy-search": "^3.2.1",
2020 "gray-matter": "^4.0.3",
2121 "html-entities": "^2.3.2",
22+ "lodash.debounce": "^4.0.8",
2223 "luxon": "^2.0.2",
2324 "next": "^12.1.5",
2425 "path-browserify": "^1.0.1",
@@ -1909,6 +1910,11 @@
19091910 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
19101911 "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
19111912 },
1913+ "node_modules/lodash.debounce": {
1914+ "version": "4.0.8",
1915+ "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
1916+ "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168="
1917+ },
19121918 "node_modules/longest-streak": {
19131919 "version": "3.0.1",
19141920 "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.0.1.tgz",
@@ -6294,6 +6300,11 @@
62946300 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
62956301 "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
62966302 },
6303+ "lodash.debounce": {
6304+ "version": "4.0.8",
6305+ "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz",
6306+ "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168="
6307+ },
62976308 "longest-streak": {
62986309 "version": "3.0.1",
62996310 "resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.0.1.tgz",
package.json+1
@@ -23,6 +23,7 @@
2323 "fuzzy-search": "^3.2.1",
2424 "gray-matter": "^4.0.3",
2525 "html-entities": "^2.3.2",
26+ "lodash.debounce": "^4.0.8",
2627 "luxon": "^2.0.2",
2728 "next": "^12.1.5",
2829 "path-browserify": "^1.0.1",