This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo.tsx
43 lines (36 loc) · 1.42 KB
/
Demo.tsx
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
import { useState } from "react";
import appleIcon from "../assets/icons/apple.png";
import bananaIcon from "../assets/icons/banana.png";
import SearchBox from "./SearchBox";
import Suggestion from "./SearchBox/Suggestion";
// NOTE: If I had more time, I would have probably built an Autocomplete component using the SearchBox component
export default function Demo() {
const [active, setActive] = useState(false);
const [inputValue, setInputValue] = useState("");
// NOTE: I would have used this hook if had some API calls or heavy computations to make
// const debouncedInputValue = useDebounce(inputValue, 500);
// NOTE: I could have also added filteration, sorting, limiting, caching, etc. to the suggestions
// but I decided to keep it simple and only satisfy the requirements for this demo
// OPTIMIZATION:
// - Add ids to the suggestions and use them as keys
// - Add label / value combination instead of just value
const suggestions: Suggestion[] = [
{ value: "Apple", icon: appleIcon },
{ value: "Banana", icon: bananaIcon },
{ value: "Eat", category: "Actions" },
];
const handleSubmit = (value: string) => {
console.log("Submitted:", value);
setInputValue("");
};
return (
<SearchBox
active={active}
setActive={setActive}
inputValue={inputValue}
setInputValue={setInputValue}
suggestions={suggestions}
onSubmit={handleSubmit}
/>
);
}