Skip to content

Commit

Permalink
fix: 검색 결과와 검색어가 동기화 안 되는 문제 개선
Browse files Browse the repository at this point in the history
  • Loading branch information
feb-dain committed Nov 16, 2023
1 parent 2bbeb67 commit 14c93e4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const useStationSearchWindow = () => {
const [searchWord, setSearchWord] = useState('');
const [debouncedSearchWord, setDebouncedSearchWord] = useState(searchWord);
const [userSearchWord, setUserSearchWord] = useState('');
const [isSubmitted, setIsSubmitted] = useState(false);

const { openLastPanel } = useNavigationBar();
const { openStationInfoWindow } = useStationInfoWindow();
Expand All @@ -46,8 +45,7 @@ export const useStationSearchWindow = () => {
setDebouncedSearchWord(searchWord);
},
[searchWord],
400,
isSubmitted
400
);

const {
Expand Down Expand Up @@ -123,7 +121,6 @@ export const useStationSearchWindow = () => {
const handleSubmitSearchWord = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
handleCloseResult();
setIsSubmitted(true);

const searchWordFromForm = new FormData(event.currentTarget).get('station-search');
const encodedSearchWord = encodeURIComponent(String(searchWordFromForm));
Expand All @@ -148,7 +145,6 @@ export const useStationSearchWindow = () => {
const handleChangeSearchWord = ({ target: { value } }: ChangeEvent<HTMLInputElement>) => {
const searchWord = encodeURIComponent(value);

setIsSubmitted(false);
handleOpenResult();
setSearchWord(searchWord);
};
Expand Down
13 changes: 2 additions & 11 deletions frontend/src/hooks/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { useEffect, useCallback } from 'react';

export const useDebounce = <T>(
func: (param: T) => void,
dependencies: string[],
delay: number,
shouldClear?: boolean
) => {
export const useDebounce = <T>(func: (param: T) => void, dependencies: string[], delay: number) => {
const callback = useCallback(func, dependencies);

useEffect(() => {
const timeout = setTimeout(callback, delay);

if (shouldClear) {
clearTimeout(timeout);
}

return () => clearTimeout(timeout);
}, [callback, delay, shouldClear]);
}, [callback, delay]);
};

0 comments on commit 14c93e4

Please sign in to comment.