Skip to content

Commit 5492104

Browse files
authored
fixes no callback function warning #200 (#206)
1 parent b375310 commit 5492104

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

lib/utils.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ var loadGoogleMapScript = function loadGoogleMapScript(googleMapsScriptBaseUrl,
2727
});
2828
}
2929

30+
var scriptUrl = new URL(googleMapsScriptUrl);
31+
scriptUrl.searchParams.set("callback", "__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__");
3032
var el = document.createElement("script");
31-
el.src = googleMapsScriptUrl;
32-
document.body.appendChild(el);
33+
el.src = scriptUrl.toString();
3334
return new Promise(function (resolve) {
34-
el.addEventListener("load", function () {
35-
return resolve();
36-
});
35+
window.__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__ = resolve;
36+
document.body.appendChild(el);
3737
});
3838
};
3939

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ export const loadGoogleMapScript = (
2424
});
2525
}
2626

27+
let scriptUrl = new URL(googleMapsScriptUrl);
28+
scriptUrl.searchParams.set(
29+
"callback",
30+
"__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__"
31+
);
2732
const el = document.createElement("script");
28-
el.src = googleMapsScriptUrl;
29-
30-
document.body.appendChild(el);
33+
el.src = scriptUrl.toString();
3134

3235
return new Promise((resolve) => {
33-
el.addEventListener("load", () => resolve());
36+
window.__REACT_GOOGLE_AUTOCOMPLETE_CALLBACK__ = resolve;
37+
document.body.appendChild(el);
3438
});
3539
};

0 commit comments

Comments
 (0)