-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using AddressAutofill in React/Next.JS app does not work #477
Comments
to solve this problem all you do is
add this on the tsconfig.json
|
Have you tried my solution? |
thank you it's fixed |
I am also having this issue. Did exactly what you did above. |
@sepehr500 is that help you or not? |
Unfortunately it didn't help |
I was able to find a quick fix, was getting the same error trying to use the AddressAutofill component in a react/typescript project. I believe because the AddressAutofill component doesn't have a type definition, typescript won't allow you to use it. I created a
hopefully this helps anyone. |
I'm using Here is a sample code for the full example. import { useState } from "react"
import { FormField, FormItem, FormLabel, FormControl, FormMessage } from "@/components/ui/form"
import { Input } from "@/components/ui/input"
import { AddressAutofill, AddressMinimap } from "@mapbox/search-js-react"
import { AddressAutofillRetrieveResponse } from "@mapbox/search-js-core"
import { useFormContext } from "react-hook-form"
const MAPBOX_TOKEN = import.meta.env.VITE_MAPBOX_TOKEN
export default function LocationFieldset() {
const { control } = useFormContext()
const [minimapFeature, setMinimapFeature] = useState<any>(null)
function handleAutofillRetrieve(response: AddressAutofillRetrieveResponse) {
console.log("onRetrieve :", response.features[0]);
if (response.features && response.features.length > 0) {
setMinimapFeature(response.features[0])
}
}
return (
<fieldset className="bg-white p-6 rounded-2xl border shadow-md space-y-4">
<h2 className="text-xl text-blue-800 font-semibold">Localisation</h2>
<FormField
control={control}
name="address"
render={({ field }) => (
<FormItem>
<FormLabel>Adresse</FormLabel>
<FormControl>
<AddressAutofill
accessToken={MAPBOX_TOKEN}
onRetrieve={handleAutofillRetrieve}
>
<Input
placeholder="Entrez votre adresse"
autoComplete="address-line1 address-line2"
{...{
value: field.value,
onChange: field.onChange,
onBlur: field.onBlur,
name: field.name,
}}
/>
</AddressAutofill>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<div className="relative border rounded h-32 w-full lg:max-w-md md:max-w-md" style={{ display: minimapFeature ? "block" : "none" }}>
<AddressMinimap
feature={minimapFeature}
satelliteToggle
canAdjustMarker
footer={true}
accessToken={MAPBOX_TOKEN}
show={!!minimapFeature}
/>
</div>
</fieldset>
)
} I think these components are outdated, the rendering is not great. You can easily recreate this feature with mapbox. Just type prompt "a simple address autofill and minimap with mapbox in react typescript" in v0.dev |
The text was updated successfully, but these errors were encountered: