Skip to content

fix: load script type errors #3405

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

Merged
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
18 changes: 8 additions & 10 deletions packages/react-google-maps-api/src/LoadScript.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
type JSX,
createRef,
PureComponent,
type ReactNode,
type RefObject,
} from 'react'
import { type JSX, PureComponent, type ReactNode } from 'react'
import invariant from 'invariant'

import {
Expand Down Expand Up @@ -44,7 +38,7 @@ export const defaultLoadScriptProps = {
class LoadScript extends PureComponent<LoadScriptProps, LoadScriptState> {
public static defaultProps = defaultLoadScriptProps

check: RefObject<HTMLDivElement> = createRef()
check: HTMLDivElement | null = null

override state = {
loaded: false,
Expand Down Expand Up @@ -97,7 +91,7 @@ class LoadScript extends PureComponent<LoadScriptProps, LoadScriptState> {
this.cleanup()

const timeoutCallback = (): void => {
if (!this.check.current) {
if (!this.check) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
delete window.google
Expand Down Expand Up @@ -234,10 +228,14 @@ class LoadScript extends PureComponent<LoadScriptProps, LoadScriptState> {
})
}

getRef = (el: HTMLDivElement | null): void => {
this.check = el
}

override render(): ReactNode {
return (
<>
<div ref={this.check} />
<div ref={this.getRef} />

{this.state.loaded
? this.props.children
Expand Down
2 changes: 1 addition & 1 deletion packages/react-google-maps-api/src/useLoadScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export function useLoadScript({
[id, url, nonce]
)

const prevLibraries = useRef<undefined | string[]>()
const prevLibraries = useRef<undefined | string[]>(undefined)

useEffect(
function checkPerformance() {
Expand Down