mapbox / mapbox-sdk-js

A JavaScript client to Mapbox services, supporting Node, browsers, and React Native
Other
717 stars 186 forks source link

Using AddressAutofill in React/Next.JS app does not work #477

Open starlight-akouri opened 8 months ago

starlight-akouri commented 8 months ago
'AddressAutofill' cannot be used as a JSX component.
  Its type 'ForwardRefExoticComponent<AddressAutofillProps & RefAttributes<unknown>>' is not a valid JSX element type.
    Type 'ForwardRefExoticComponent<AddressAutofillProps & RefAttributes<unknown>>' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.
      Type 'ReactElement<any, string | JSXElementConstructor<any>> | null' is not assignable to type 'ReactNode'.
        Type 'ReactElement<any, string | JSXElementConstructor<any>>' is not assignable to type 'ReactNode'.
          Property 'children' is missing in type 'ReactElement<any, string | JSXElementConstructor<any>>' but required in type 'ReactPortal'.ts(2786)
galihpermana29 commented 7 months ago

to solve this problem all you do is

npm install @types/react

add this on the tsconfig.json

"paths": { "react": ["./node_modules/@types/react"], }

thomaslemoine commented 6 months ago

Hi, I have the same error with vitejs, ts, react

Capture d’écran 2024-05-13 à 19 08 05
galihpermana29 commented 6 months ago

Have you tried my solution?

thomaslemoine commented 6 months ago

Have you tried my solution?

thank you it's fixed

NateDawg90 commented 6 months ago

This is also not working for me. My app is Next/React/TS. Error: Screenshot 2024-05-17 at 10 36 34 AM My tsconfig, and package.json respectively: Screenshot 2024-05-17 at 10 36 58 AM Screenshot 2024-05-17 at 10 37 06 AM

galihpermana29 commented 5 months ago

my tsconfig.json

Screenshot 2024-05-29 at 22 25 52

package.json

Screenshot 2024-05-29 at 22 26 23

I've tried on couple project and it works to me

sepehr500 commented 4 months ago

I am also having this issue. Did exactly what you did above.

galihsynergy commented 4 months ago

@sepehr500 is that help you or not?

sepehr500 commented 4 months ago

@sepehr500 is that help you or not?

Unfortunately it didn't help

Marquessmalley commented 3 months ago

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 declarations.d.ts file in my /src folder and added :

declare module "@mapbox/search-js-react" { export const AddressAutofill: React.FC<any>; // Adjust types if more specific ones are available }

hopefully this helps anyone.