| Server IP : 13.235.167.51 / Your IP : 216.73.217.116 Web Server : Apache System : Linux machinox-server 6.17.0-1013-aws #13~24.04.1-Ubuntu SMP Fri Apr 24 21:36:58 UTC 2026 aarch64 User : root ( 0) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/control.machinox.in/node_modules/@react-google-maps/api/src/ |
Upload File : |
# 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 />
}
```