diff --git a/src/components/LuxurySelect.tsx b/src/components/LuxurySelect.tsx index 0cc21bb..ec0d4e0 100644 --- a/src/components/LuxurySelect.tsx +++ b/src/components/LuxurySelect.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useState, useRef, useEffect } from 'react'; +import { useState, useRef, useEffect, useMemo } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { ChevronDown, Check } from 'lucide-react'; import { cn } from '@/lib/utils'; @@ -33,12 +33,19 @@ export default function LuxurySelect({ const [searchTerm, setSearchTerm] = useState(''); const containerRef = useRef(null); const inputRef = useRef(null); - const selectedOption = options.find(opt => opt.value === value); - const filteredOptions = options.filter(opt => - opt.label.toLowerCase().includes(searchTerm.toLowerCase()) + const selectedOption = useMemo(() => + options.find(opt => opt.value === value), + [options, value] ); + const filteredOptions = useMemo(() => { + const lowerSearchTerm = searchTerm.toLowerCase(); + return options.filter(opt => + opt.label.toLowerCase().includes(lowerSearchTerm) + ); + }, [options, searchTerm]); + useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (containerRef.current && !containerRef.current.contains(event.target as Node)) {