-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from imi21123/test
Feat: 축제 부스 검색 페이지 제작
- Loading branch information
Showing
4 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useState, useEffect, useRef } from "react"; | ||
import { IMAGES } from "../../constants/images"; | ||
import "./StoreSearch.css"; | ||
import Header from "../../components/views/Header/Header"; | ||
import NavBar from "../../components/views/NavBar/NavBar"; | ||
import StoreList from "../../components/views/StoreList/StoreList"; | ||
|
||
function FestivalBoothSearch() { | ||
const [searchTerm, setSearchTerm] = useState(""); | ||
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(searchTerm); | ||
const debounceDelay = 500; // 디바운스 지연 시간 | ||
const inputRef = useRef(null); | ||
|
||
// 사용자 입력 처리 | ||
const handleInputChange = (e) => { | ||
setSearchTerm(e.target.value); | ||
// console.log("검색어:", searchTerm); | ||
}; | ||
|
||
// 디바운싱 구현 | ||
useEffect(() => { | ||
const handler = setTimeout(() => { | ||
setDebouncedSearchTerm(searchTerm); | ||
console.log("디바운싱:", searchTerm); | ||
}, debounceDelay); | ||
|
||
// 컴포넌트가 unmount되거나 다음 useEffect가 실행되기 전에 타이머를 정리 | ||
return () => { | ||
clearTimeout(handler); | ||
}; | ||
}, [searchTerm, debounceDelay]); | ||
|
||
return ( | ||
<div className="store_search"> | ||
<Header headerProps={{ pageName: "축제 주점 검색" }} /> | ||
|
||
<form className="store_search_form" onSubmit={(e) => e.preventDefault()}> | ||
<img src={IMAGES.search} alt="search" /> | ||
<input | ||
type="text" | ||
className="store_search_input" | ||
placeholder="Search" | ||
value={searchTerm} | ||
onChange={handleInputChange} | ||
ref={inputRef} | ||
/> | ||
</form> | ||
|
||
{/* Debounced search term을 사용하여 StoreList에 prop으로 전달 */} | ||
<StoreList searchTerm={debouncedSearchTerm} booth={true} /> | ||
|
||
<NavBar /> | ||
</div> | ||
); | ||
} | ||
|
||
export default FestivalBoothSearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters