File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
examples/autocomplete-suggestions Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 55 "license" : " MIT" ,
66 "dependencies" : {
77 "@reach/combobox" : " 0.16.1" ,
8+ "lodash.debounce" : " 4.0.8" ,
89 "next" : " latest" ,
910 "react" : " 18.1.0" ,
1011 "react-dom" : " 18.1.0" ,
Original file line number Diff line number Diff line change 1- import { useState } from "react"
1+ import { useMemo , useState } from "react"
22import fetcher from '../libs/fetcher'
33import {
44 Combobox ,
77 ComboboxList ,
88 ComboboxOption
99} from '@reach/combobox'
10+ import debounce from 'lodash.debounce'
1011
1112import useSWR from 'swr'
1213
@@ -17,17 +18,21 @@ export default function Index() {
1718 fetcher
1819 )
1920
20- function handleSearchTermChange ( event ) {
21+ function handleChange ( event ) {
2122 setSearchTerm ( event . target . value )
2223 }
2324
25+ const debouncedHandleChange = useMemo (
26+ ( ) => debounce ( handleChange , 500 )
27+ , [ ] ) ;
28+
2429 return (
2530 < div style = { { textAlign : 'center' } } >
2631 < h1 > Country Search</ h1 >
2732 < Combobox >
2833 < ComboboxInput
2934 className = "country-search-input"
30- onChange = { handleSearchTermChange }
35+ onChange = { debouncedHandleChange }
3136 aria-label = "Countries"
3237 />
3338 { countries && countries . length > 0 && (
You can’t perform that action at this time.
0 commit comments