PHP 7.4.33
Preview: useLoadScript.md Size: 1.39 KB
/var/www/sitesecurity.bitkit.dk/httpdocs/node_modules/@react-google-maps/api/src/useLoadScript.md
# Requires React 16.8+

Underlying React hook that can be used for a fine-grained approach instead of opinionated [LoadScriptNext](#loadscriptnext).

It's the alternative variant of LoadScript that tries to solve the problem of "google is not defined" error by removing the cleanup routines ([read more](https://github.com/JustFly1984/react-google-maps-api/pull/143)).

```js static
import { useCallback } from 'react'
import { GoogleMap, useLoadScript } from '@react-google-maps/api'

const options = {
  zoomControlOptions: {
    position: google.maps.ControlPosition.RIGHT_CENTER // ,
    // ...otherOptions
  }
}

function MyComponent() {
  const { isLoaded, loadError } = useLoadScript({
    googleMapsApiKey: "YOUR_API_KEY" // ,
    // ...otherOptions
  })

  const renderMap = () => {
    // wrapping to a function is useful in case you want to access `window.google`
    // to eg. setup options or create latLng object, it won't be available otherwise
    // feel free to render directly if you don't need that
    const onLoad = useCallback(
      function onLoad (mapInstance) {
        // do something with map Instance
      }
    )
    return <GoogleMap
      options={options}
      onLoad={onLoad}
    >
      {
        // ...Your map components
      }
    </GoogleMap>
  }

  if (loadError) {
    return <div>Map cannot be loaded right now, sorry.</div>
  }

  return isLoaded ? renderMap() : <Spinner />
}
```

Directory Contents

Dirs: 4 × Files: 15
Name Size Perms Modified Actions
- drwxr-xr-x 2026-04-28 09:11:40
Edit Download
docs DIR
- drwxr-xr-x 2026-04-28 09:11:40
Edit Download
utils DIR
- drwxr-xr-x 2026-04-28 09:11:40
Edit Download
__tests__ DIR
- drwxr-xr-x 2026-04-28 09:11:40
Edit Download
939 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
829 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
16.12 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.56 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
6.24 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
198 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.29 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
479 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
8.56 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
270 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
275 B lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.37 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
2.71 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
1.39 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
3.50 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).