@ikeboy003/address
v0.1.1
Published
Headless Google Places address autocomplete: configure-at-import from env, framework-agnostic loader + parser, optional React hook/component. Returns the formatted string AND structured parts (street1/city/state/postal/country) that drop straight onto a c
Downloads
16
Maintainers
Readme
@ikeboy003/address
Headless Google Places address autocomplete. One public, referrer-restricted browser key serves every site — no backend, no D1 cache (the JS widget is session-billed in the browser and Google's ToS forbids storing predictions).
Over a raw autocomplete it returns structured, ShipTo-shaped parts so a checkout form auto-fills street/city/state/zip instead of just a display string.
Setup
Set NEXT_PUBLIC_GOOGLE_MAPS_API_KEY (or configureAddress({ apiKey })). Restrict the
key to your domains + the Maps JavaScript API + Places library in the Google console.
Hook (headless — you own the input)
import { useAddressAutocomplete } from "@ikeboy003/address/react";
const { inputRef, error } = useAddressAutocomplete({
onSelect: (r) => setShip((s) => ({ ...s, ...r.parts })), // parts ⊂ ShipTo
});
<input ref={inputRef} placeholder="Start typing your address…" className={inputCls} />Component
import { AddressAutocomplete } from "@ikeboy003/address/react";
<AddressAutocomplete
className={inputCls}
placeholder="Street address"
onSelect={(r) => setShip((s) => ({ ...s, ...r.parts }))}
onRawChange={(v) => setStreet1(v)}
/>AddressResult: { formatted, parts: { street1, street2, city, state, postal, country }, placeId }.
placeId is the only Google field allowed to be persisted long-term.
