You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a simple react component for working with google [autocomplete](https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete)
@@ -13,11 +17,11 @@ As of version 1.2.4, you can now pass an `apiKey` prop to automatically load the
13
17
```js
14
18
<AutoComplete
15
19
apiKey={YOUR_GOOGLE_MAPS_API_KEY}
16
-
onPlaceSelected={() =>"do something on select"}
20
+
onPlaceSelected={(place) =>console.log(place)}
17
21
/>
18
22
```
19
23
20
-
Alternatively if not passing the `apiKey` prop, you can include google autocomplete link api in your app. Somewhere in index.html or somewhere else.
24
+
Alternatively if not passing the `apiKey` prop, you can include google autocomplete link api in your app. Somewhere in index.html or somewhere else. More info [here](https://developers.google.com/maps/documentation/places/web-service/autocomplete)
21
25
22
26
```html
23
27
<script
@@ -26,41 +30,111 @@ Alternatively if not passing the `apiKey` prop, you can include google autocompl
26
30
></script>
27
31
```
28
32
29
-
## Example
33
+
## Props
34
+
35
+
-`apiKey`: pass to automatically load the Google maps scripts. The api key can be found in your [google cloud console.](https://developers.google.com/maps/documentation/javascript/get-api-key)
36
+
37
+
-`ref`: [React ref](https://reactjs.org/docs/hooks-reference.html#useref) to be assigned the underlying text input ref.
38
+
39
+
-`autocompleteRef`: [React ref](https://reactjs.org/docs/hooks-reference.html#useref) to be assigned the [google autocomplete instance](https://developers.google.com/maps/documentation/javascript/reference/places-widget#Autocomplete).
40
+
41
+
-`onPlaceSelected: (place: `[PlaceResult](https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceResult)`, inputRef, autocompleteRef) => void`: The function gets invoked every time a user chooses location.
-`options.fields`: By default it uses `address_components`, `geometry.location`, `place_id`, `formatted_address`.
47
+
48
+
-`inputAutocompleteValue`: Autocomplete value to be set to the underlying input.
49
+
50
+
-`googleMapsScriptBaseUrl`: Provide custom google maps url. By default `https://maps.googleapis.com/maps/api/js`
51
+
52
+
-`defaultValue` prop is used for setting up the default value e.g `defaultValue={'Amsterdam'}`.
53
+
54
+
You can pass any prop specified for the hmtl [input tag](https://www.w3schools.com/tags/tag_input.asp). You can also set [options.fields](https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceResult) prop if you need extra information, now it defaults to basic data in order to control expenses.
The component has one function called `onPlaceSelected`. The function gets invoked every time a user chooses location.
59
-
A `types` props means type of places in [google place API](https://developers.google.com/places/web-service/autocomplete#place_types). By default it uses (cities).
60
-
A [componentRestrictions](https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions) prop by default is empty.
61
-
A [bounds](https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions) prop by default is empty.
62
-
You also can pass any props you want to the final input. You can also set [fields](https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceResult) prop if you need extra information, now it defaults to basic data in order to control expenses.
63
-
The `options`(optional) prop is the optional configuration to your Autocomplete instance. You can see full options [here](https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete)
129
+
### More examples(dynamic props, MaterialUI) how to use the lib could be found in `examples/index.js`
130
+
131
+
[Video of the example](https://api.monosnap.com/file/download?id=vIjRwTxVyMj0Sd2Gjhsfie2SPk1y4l)
0 commit comments