ErrorPro / react-google-autocomplete

React components for google places API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The selection is not maintained, only if I add code inside onPlaceSelected

nappalm opened this issue · comments

Because my current code does not work, however if I use only a console.log within onPlaceSelected the selection in the input is maintained correctly.

<Controller
              name="location"
              render={({ field, fieldState: { error } }) => {
                return (
                  <div>
                    <span style={{ color: 'black' }}>Location</span>
                    <Input
                      fullWidth
                      inputComponent={({ inputRef, onFocus, onBlur, ...props }) => (
                        <Autocomplete
                          apiKey="..."
                          {...props}
                          onPlaceSelected={(selected) => {
                            const lat = selected.geometry.location.lat();
                            const lng = selected.geometry.location.lng();

                            field.onChange({
                              lat,
                              lng,
                              formatted_address: selected.formatted_address,
                            });
                          }}
                        />
                      )}
                    />
                  </div>
                );
              }}
            />

Gif error:
ezgif-5-1ca7c007e4

First idea: did you checked if your Input or Controller component is rerendered for some reason, so it resets the value?