Amazon Search 코드 설명

peace kim·2023년 11월 29일
0

TypeScript

목록 보기
7/7
  {searchQuery && (
            <div className="absolute left-0 top-12 w-full mx-auto max-h-96 bg-gray-200 rounded-lg overflow-y-scroll cursor-pointer text-black">
              {filteredProducts.length > 0 ? (
                <>
                  {searchQuery &&
                    filteredProducts.map((item: StoreProduct) => (
                      <Link
                        key={item._id}
                        className="w-full border-b-[1px] border-b-gray-400 flex items-center gap-4"
                        href={{
                          pathname: `${item._id}`,
                          query: {
                            _id: item._id,
                            brand: item.brand,
                            category: item.category,
                            description: item.description,
                            image: item.image,
                            isNew: item.isNew,
                            oldPrice: item.oldPrice,
                            price: item.price,
                            title: item.title,
                          },
                        }}
                        onClick={() => setSearchQuery("")}
                      >
                        <SearchProducts item={item} />
                      </Link>
                    ))}
                </>
              ) : (
                <div className="bg-gray-50 flex items-center justify-center py-10 rounded-lg shadow-lg">
                  <p className="text-xl font-semibold animate-bounce">
                    Nothing is matches with your search keywords. Please try
                    again!
                  </p>
                </div>
              )}
            </div>
          )}

조건부 렌더링

{searchQuery && (...)}.
괄호 안의 코드 블록이 searchQuery진실인 경우에만 렌더링

드롭다운

클래스가 있는 요소 absolute left-0 top-12 w-full mx-auto max-h-96 bg-gray-200 rounded-lg overflow-y-scroll cursor-pointer text-black. 검색 결과를 표시하는 드롭다운 컨테이너

필터링
filteredProducts. 각 제품( )에 대해 Next.js( ${item._id}``) 를 사용하여 특정 제품 페이지로 이동하는 것처럼 보이는 요소를 item생성

SearchProducts 구성 요소 : 제품 정보는 SearchProducts각 제품의 세부 정보를 렌더링하는 구성 요소로 전달

profile
개발자

0개의 댓글

관련 채용 정보