Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-google-places

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-google-places

React hook that consumes Google Places API returning both autocomplete and geocoding callback method

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

React Hook useGooglePlaces

Hook to consume Google Places API returning both autocomplete with debounce and geocoding callback method

Flow

onChange<keyword> -> Fetch autocomplete -> results -> onSelect -> Fetch geocoding -> onSelect.callback<result>

Installation

  • TODO

Options

PropDescriptionDefault
apiKeyClient-side google api key (documentation)[https://developers.google.com/places/web-service/get-api-key].None
delaydebounce OnChange (milliseconds).0

Methods

PropDescriptionType
loadingTriggers each request.boolean
resultsNormalized Google API (predictions)[https://developers.google.com/places/web-service/autocomplete#place_autocomplete_responses].{title, subtitle, placeId, description}
onChangeFunction that triggers autocomplete.function<string>
onSelectOptional function that triggers geocoding executing a callback with coordinates and details.function<{placeId}, callback<geocoding-payload>

Usage

Component
  const { loading, results, onChange, onSelect } = useGooglePlaces({
    apiKey: 'my-google-api-key',
    delay: 400,
  });

  ...

  const onPress = item => {
    onSelect(item, ({ coordinates }) => {
      dispatch({
        type: SET_LOCATION,
        payload: coordinates,
      });
    });
  };

  ...

  <FlatList
    data={results}
    renderItem={({ item }) => (
      <LocationItem
        title={item.title}
        subtitle={item.subtitle}
        onPress={onPress}
      />
    )}
  />

Keywords

FAQs

Package last updated on 23 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc