Search code examples
reactjsgoogle-places-autocompletesurveyjs

Survey fields get cleared when updating value on a custom widget made with PlacesAutocomplete


I am using SurveyJS to quickly build a survey form in React/Redux.

I implemented a custom widget using a React component for Google Maps Places Autocomplete. My problem is that once suggestions appear and the field state changes, the contents of all the other survey fields get cleared. Is there a way to prevent it?

Here's what I did to integrate React Places Autocomplete into the survey as a custom widget.


Solution

  • As soon as you select the Address field the onChange is called, the component loses the state for the other fields.

    "setState() will always lead to a re-render unless shouldComponentUpdate() returns false. If mutable objects are being used and conditional rendering logic cannot be implemented in shouldComponentUpdate(), calling setState() only when the new state differs from the previous state will avoid unnecessary re-renders." from reactjs.org