-
Notifications
You must be signed in to change notification settings - Fork 113
/
debounce.js
53 lines (50 loc) · 1.35 KB
/
debounce.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { useState } from "react";
import { Input, List } from "antd";
import useGoogle from "react-google-autocomplete/lib/usePlacesAutocompleteService";
export const Debounce = ({ a }) => {
const {
placePredictions,
getPlacePredictions,
isPlacePredictionsLoading,
} = useGoogle({
apiKey: process.env.REACT_APP_GOOGLE,
});
const [value, setValue] = useState("");
return (
<div style={{ width: "250px" }}>
<span>Debounced</span>
<Input.Search
style={{ color: "black" }}
value={value}
placeholder="Debounce 500 ms"
onChange={(evt) => {
getPlacePredictions({ input: evt.target.value });
setValue(evt.target.value);
}}
loading={isPlacePredictionsLoading}
/>
<div
style={{
marginTop: "20px",
width: "200px",
height: "200px",
display: "flex",
flex: "1",
flexDirection: "column",
marginBottom: "100px",
}}
>
{!isPlacePredictionsLoading && (
<List
dataSource={placePredictions}
renderItem={(item) => (
<List.Item onClick={() => setValue(item.description)}>
<List.Item.Meta title={item.description} />
</List.Item>
)}
/>
)}
</div>
</div>
);
};