Giter VIP home page Giter VIP logo

Comments (4)

Tintef avatar Tintef commented on September 6, 2024

@gabe2code I'm not a Typescript user myself, but I'll check this as soon as I get a change.

from react-google-places-autocomplete.

Tintef avatar Tintef commented on September 6, 2024

@gabe2code Noticed it's a bug on the typescript definition for the props. Working on a fix now

from react-google-places-autocomplete.

Tintef avatar Tintef commented on September 6, 2024

@gabe2code Thanks for catching and reporting this!

In the new release (2.0.4) you can use it like this:

import React from 'react';
import GooglePlacesAutocomplete, { geocodeByPlaceId } from 'react-google-places-autocomplete';
import 'react-google-places-autocomplete/dist/index.min.css';

class App extends React.Component<any, {}> {
  onSelect = (selection: any):void => {
    geocodeByPlaceId(selection.place_id)
      .then(results => results[0])
      .then(latLng => console.log('Success', latLng))
      .catch(error => console.error('Error', error));
  };

  renderInput = (props: any):JSX.Element => <input {...props} />

  renderSuggestions = (active: number, suggestions: Array<any>, onSelect: (suggestion: any, event: any) => void):JSX.Element => (
    <div>
      {
        suggestions.map(sugg => (
          <div
            key={sugg.id}
            className="suggestion"
            onClick={(event) => onSelect(sugg, event)}
          >
            {sugg.description}
          </div>
        ))
      }
    </div>
  )

  render(): React.ReactElement {
    return (
      <div className="App">
        <GooglePlacesAutocomplete
          apiKey="*******"
          onSelect={this.onSelect}
          renderInput={this.renderInput}
          renderSuggestions={this.renderSuggestions}
        />
      </div>
    );
  }
}

export default App;

from react-google-places-autocomplete.

gabe2code avatar gabe2code commented on September 6, 2024

Hi @Tintef , looks very good, thanks for the help 👍

from react-google-places-autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.