import { useState, useEffect, useRef } from 'react'; import { Search } from 'lucide-react'; interface SearchInputProps { value: string; onChange: (value: string) => void; placeholder?: string; debounceMs?: number; } export function SearchInput({ value, onChange, placeholder = 'Buscar...', debounceMs = 300, }: SearchInputProps) { const [localValue, setLocalValue] = useState(value); const timerRef = useRef>(undefined); useEffect(() => { setLocalValue(value); }, [value]); function handleChange(newValue: string) { setLocalValue(newValue); if (timerRef.current) clearTimeout(timerRef.current); timerRef.current = setTimeout(() => { onChange(newValue); }, debounceMs); } useEffect(() => { return () => { if (timerRef.current) clearTimeout(timerRef.current); }; }, []); return (
handleChange(e.target.value)} placeholder={placeholder} className="w-full rounded border bg-bg pl-9 pr-3 py-2 text-body text-primary placeholder:text-text-muted focus:border-isis-blue focus:outline-none" />
); }