Skip to content

Commit aa22f03

Browse files
debounce
1 parent 93ce8d0 commit aa22f03

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/app/components/searchbar.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,26 @@ const SearchBar = () => {
2222
const debouncedSearch = useCallback(
2323
debounce(async (text: string) => {
2424
if (text.length > 1) {
25-
2625
try {
27-
const searchResponse = await axios.get("http://localhost:3000/api/search", {
26+
const searchResponse = await axios.get("/api/search", {
2827
params: { text },
2928
});
30-
29+
3130
const { res: encryptedSearchResponse } = searchResponse.data;
3231
const decryptedSearchResponse = cryptr.decrypt(encryptedSearchResponse);
33-
// console.log("Decrypted Search Response:", decryptedSearchResponse);
34-
3532
const { subjects } = JSON.parse(decryptedSearchResponse);
3633
const suggestionList = subjects.map((subjectObj: { subject: string }) => subjectObj.subject);
3734
setSuggestions(suggestionList);
3835
} catch (error) {
39-
setError("Error fetching suggestions");
40-
36+
const typedError = error as AxiosError<{ message?: string }>;
37+
const errorMessage = typedError.response?.data?.message ?? "Error fetching suggestions";
38+
setError(errorMessage);
4139
}
4240
} else {
4341
setSuggestions([]);
4442
}
45-
}, 1000),
46-
[]
43+
}, 1000),
44+
[cryptr, axios]
4745
);
4846

4947
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {

0 commit comments

Comments
 (0)