This repository was archived by the owner on Jan 14, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Expand file tree Collapse file tree 3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 26
26
"gatsby-source-filesystem" : " ^2.0.32" ,
27
27
"gatsby-transformer-remark" : " ^2.3.12" ,
28
28
"gatsby-transformer-sharp" : " ^2.1.18" ,
29
+ "lodash.debounce" : " ^4.0.8" ,
29
30
"prismjs" : " ^1.16.0" ,
30
31
"react" : " ^16.8.6" ,
31
32
"react-dom" : " ^16.8.6" ,
Original file line number Diff line number Diff line change 1
1
import React , { useState , useEffect } from "react"
2
+ import debounce from "lodash.debounce"
2
3
import Layout from "../components/layout"
3
4
import SearchForm from "../components/searchForm"
4
5
import SearchResults from "../components/searchResults"
@@ -9,12 +10,17 @@ const Search = ({ data, location }) => {
9
10
10
11
useEffect ( ( ) => {
11
12
if ( searchQuery && window . __LUNR__ ) {
12
- window . __LUNR__ . __loaded . then ( lunr => {
13
+ const debouncedSearch = debounce ( async ( ) => {
14
+ const lunr = await window . __LUNR__ . __loaded
13
15
const refs = lunr . en . index . search ( searchQuery )
14
16
const posts = refs . map ( ( { ref } ) => lunr . en . store [ ref ] )
17
+
15
18
setResults ( posts )
16
- } )
19
+ } , 500 )
20
+
21
+ debouncedSearch ( )
17
22
}
23
+
18
24
if ( ! searchQuery ) setResults ( [ ] )
19
25
} , [ location . search ] )
20
26
Original file line number Diff line number Diff line change @@ -6945,6 +6945,11 @@ lodash.clonedeep@^4.5.0:
6945
6945
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
6946
6946
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=
6947
6947
6948
+ lodash.debounce@^4.0.8 :
6949
+ version "4.0.8"
6950
+ resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
6951
+ integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
6952
+
6948
6953
lodash.escaperegexp@^4.1.2 :
6949
6954
version "4.1.2"
6950
6955
resolved "https://registry.yarnpkg.com/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347"
You can’t perform that action at this time.
0 commit comments