Skip to content

Commit

Permalink
Fix second script loading issue, update docs, bump 2.0.1 (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErrorPro authored Apr 20, 2021
1 parent 571bdb7 commit b235344
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
![](/docs/example.gif)

![](https://img.badgesize.io/ErrorPro/react-google-autocomplete/master/lib/index.js?compression=gzip&label=gzip)
![](https://img.badgesize.io/ErrorPro/react-google-autocomplete/master/lib/index.js?compression=brotli&label=brotli)
![](https://badgen.net/npm/dm/react-google-autocomplete?labelColor=49516F&color=8994BC)
[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://GitHub.com/ErrorPro/react-google-autocomplete/master/LICENSE)

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

### More examples(dynamic props, MaterialUI) how to use the lib could be found in `examples/index.js`

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

### TODO

Expand Down
Binary file added docs/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ function ReactGoogleAutocomplete(props) {

if (scriptElement) {
return new Promise(function (resolve) {
// in case we already have a script on the page and it's loaded we resolve
if (typeof google !== "undefined") return resolve();

// otherwise we wait until it's loaded and resolve
scriptElement.addEventListener("load", function () {
return resolve();
});
Expand Down Expand Up @@ -165,9 +169,11 @@ ReactGoogleAutocomplete.propTypes = {
ref: _propTypes2.default.oneOfType([
// Either a function
_propTypes2.default.func,
// Or the instance of a DOM native element (see the note about SSR)
// Or the instance of a DOM native element
_propTypes2.default.shape({ current: _propTypes2.default.instanceOf(Element) })]),
autocompleteRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.shape({ current: _propTypes2.default.instanceOf(Element) })]),
autocompleteRef: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.shape({
current: _propTypes2.default.any
})]),
googleMapsScriptBaseUrl: _propTypes2.default.string,
onPlaceSelected: _propTypes2.default.func,
inputAutocompleteValue: _propTypes2.default.string,
Expand Down
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function ReactGoogleAutocomplete(props) {

if (scriptElement) {
return new Promise((resolve) => {
// in case we already have a script on the page and it's loaded we resolve
if (typeof google !== "undefined") return resolve();

// otherwise we wait until it's loaded and resolve
scriptElement.addEventListener("load", () => resolve());
});
}
Expand Down Expand Up @@ -165,7 +169,9 @@ ReactGoogleAutocomplete.propTypes = {
]),
autocompleteRef: PropTypes.oneOfType([
PropTypes.func,
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
PropTypes.shape({
current: PropTypes.any,
}),
]),
googleMapsScriptBaseUrl: PropTypes.string,
onPlaceSelected: PropTypes.func,
Expand Down

0 comments on commit b235344

Please sign in to comment.