import React, { useState, useEffect } from "react"; export default function AddressAutocomplete({ onSelect }) { const [input, setInput] = useState(""); const [options, setOptions] = useState([]); useEffect(() => { if (input.length < 3) { setOptions([]); return; } const ctrl = new AbortController(); fetch(`/api/autocomplete?input=${encodeURIComponent(input)}`, { signal: ctrl.signal, }) .then((res) => res.json()) .then((json) => setOptions(json.predictions || [])) .catch(() => {}) .finally(() => {}); return () => ctrl.abort(); }, [input]); return (
setInput(e.target.value)} style={{ width: "100%", padding: "0.5rem", boxSizing: "border-box" }} /> {options.length > 0 && ( )}
); }