Socket
Socket
Sign inDemoInstall

use-google-maps-script

Package Overview
Dependencies
4
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-google-maps-script

This hook can be used to load the Google Maps API script as a hook. It is heavily based on a hook provided by [@react-google-maps/api](https://github.com/JustFly1984/react-google-maps-api), but can be used when you don't need the rest of Google Maps provi


Version published
Weekly downloads
1.2K
decreased by-32.35%
Maintainers
1
Install size
85.9 kB
Created
Weekly downloads
 

Readme

Source

useGoogleMapsScript

This hook can be used to load the Google Maps API script as a hook. It is heavily based on a hook provided by @react-google-maps/api, but can be used when you don't need the rest of Google Maps provided by this library.

import { ReactNode } from 'react';
import { useGoogleMapsScript, Libraries } from 'use-google-maps-script';

export function App() {
  return (
    <LoadScript googleMapsApiKey={process.env.NEXT_PUBLIC_GOOGLE_API_KEY}>
      <SearchBox />
    </LoadScript>
  );
}

interface LoadScriptProps {
  googleMapsApiKey: string;
  children: ReactNode;
}

// Important to either declare outside component or memoize to avoid re-renders
const libraries: Libraries = ['places'];

function LoadScript({ googleMapsApiKey, children }: LoadScriptProps) {
  const { isLoaded, loadError } = useLoadScript({
    googleMapsApiKey,
    libraries,
  });

  if (!isLoaded) return <div>Loading script</div>;
  if (loadError) return <div>Error loading script</div>;
  return children;
}

function SearchBox() {
  // Could be used with https://use-places-autocomplete.netlify.app/
  return <div>Search Box which relies on google maps script.</div>;
}

FAQs

Last updated on 08 Nov 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc