Skip to content

Commit d16fec1

Browse files
committed
Fix second script loading issue, update docs, bump 2.0.1 (#95)
1 parent 571bdb7 commit d16fec1

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
![](/docs/example.gif)
2+
13
![](https://img.badgesize.io/ErrorPro/react-google-autocomplete/master/lib/index.js?compression=gzip&label=gzip)
24
![](https://img.badgesize.io/ErrorPro/react-google-autocomplete/master/lib/index.js?compression=brotli&label=brotli)
5+
![](https://badgen.net/npm/dm/react-google-autocomplete?labelColor=49516F&color=8994BC)
36
[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://GitHub.com/ErrorPro/react-google-autocomplete/master/LICENSE)
47

58
## React google autocomplete
@@ -130,9 +133,7 @@ const AutocompleteTS: FC<ReactGoogleAutocomplete> = Autocomplete as FC<ReactGoog
130133
<AutocompleteTS apiKey="123" />;
131134
```
132135

133-
### More examples(dynamic props, MaterialUI) how to use the lib could be found in `examples/index.js`
134-
135-
[Video of the example](https://api.monosnap.com/file/download?id=vIjRwTxVyMj0Sd2Gjhsfie2SPk1y4l)
136+
More examples(dynamic props, MaterialUI) how to use the lib could be found in `docs/examples.js`
136137

137138
### TODO
138139

docs/example.gif

194 KB
Loading
File renamed without changes.

lib/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ function ReactGoogleAutocomplete(props) {
6060

6161
if (scriptElement) {
6262
return new Promise(function (resolve) {
63+
// in case we already have a script on the page and it's loaded we resolve
64+
if (typeof google !== "undefined") return resolve();
65+
66+
// otherwise we wait until it's loaded and resolve
6367
scriptElement.addEventListener("load", function () {
6468
return resolve();
6569
});
@@ -165,9 +169,11 @@ ReactGoogleAutocomplete.propTypes = {
165169
ref: _propTypes2.default.oneOfType([
166170
// Either a function
167171
_propTypes2.default.func,
168-
// Or the instance of a DOM native element (see the note about SSR)
172+
// Or the instance of a DOM native element
169173
_propTypes2.default.shape({ current: _propTypes2.default.instanceOf(Element) })]),
170-
autocompleteRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.shape({ current: _propTypes2.default.instanceOf(Element) })]),
174+
autocompleteRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.shape({
175+
current: _propTypes2.default.any
176+
})]),
171177
googleMapsScriptBaseUrl: _propTypes2.default.string,
172178
onPlaceSelected: _propTypes2.default.func,
173179
inputAutocompleteValue: _propTypes2.default.string,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-google-autocomplete",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "React component for google autocomplete.",
55
"main": "index.js",
66
"types": "index.d.ts",

src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ function ReactGoogleAutocomplete(props) {
4242

4343
if (scriptElement) {
4444
return new Promise((resolve) => {
45+
// in case we already have a script on the page and it's loaded we resolve
46+
if (typeof google !== "undefined") return resolve();
47+
48+
// otherwise we wait until it's loaded and resolve
4549
scriptElement.addEventListener("load", () => resolve());
4650
});
4751
}
@@ -165,7 +169,9 @@ ReactGoogleAutocomplete.propTypes = {
165169
]),
166170
autocompleteRef: PropTypes.oneOfType([
167171
PropTypes.func,
168-
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
172+
PropTypes.shape({
173+
current: PropTypes.any,
174+
}),
169175
]),
170176
googleMapsScriptBaseUrl: PropTypes.string,
171177
onPlaceSelected: PropTypes.func,

0 commit comments

Comments
 (0)