Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ON-40754 # Added useGoogleJsApiLoader() hook #677

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `<FormElementGoogleAddress />`
- `useGoogleJsApiLoader()` hook

### Changed

Expand Down
15 changes: 2 additions & 13 deletions src/hooks/useGoogle.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import * as React from 'react'
import { useJsApiLoader, Libraries } from '@react-google-maps/api'
import useGoogleMapsApiKey from './useGoogleMapsApiKey'
import useGoogleJsApiLoader from './useGoogleJsApiLoader'

export default function useGoogle() {
const key = useGoogleMapsApiKey()

const libraries = React.useMemo<Libraries>(
() => ['maps', 'marker', 'places'],
[],
)

const { isLoaded } = useJsApiLoader({
googleMapsApiKey: key ?? '',
libraries,
})

return { isLoaded }
return useGoogleJsApiLoader(key ?? '')
}
20 changes: 20 additions & 0 deletions src/hooks/useGoogleJsApiLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from 'react'
import { useJsApiLoader, Libraries } from '@react-google-maps/api'

/**
* Load the google maps JavaScript API libraries used by this package.
*
* @param key Google Maps API Key
* @returns
*/
export default function useGoogleJsApiLoader(key: string) {
const libraries = React.useMemo<Libraries>(
() => ['maps', 'marker', 'places'],
[],
)

return useJsApiLoader({
googleMapsApiKey: key,
libraries,
})
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export {
export { default as useLoadResourcesState } from './hooks/useLoadResourcesState'
export { default as useFormSubmissionState } from './hooks/useFormSubmissionState'
export { default as useFormSubmissionAutoSaveState } from './hooks/useFormSubmissionAutoSaveState'
export { default as useGoogleJsApiLoader } from './hooks/useGoogleJsApiLoader'

export { default as ProgressBar } from './components/renderer/ProgressBar'
export { default as PaymentReceipt } from './PaymentReceipt'
Expand Down