Tintef / react-google-places-autocomplete

React Google Places Autocomplete input -- fully customizable
https://tintef.github.io/react-google-places-autocomplete
MIT License
376 stars 161 forks source link

Error accessing 'place_id' property when rendering component dynamically #328

Open Shaxadhere opened 1 year ago

Shaxadhere commented 1 year ago

When using the component normally or having multiple instances of it on the same form and page, it works fine. However, an issue arises when rendering the component dynamically, such as when mapping it with an array and adding one more item to the array. The following error occurs:

Cannot read properties of undefined (reading 'place_id')
TypeError: Cannot read properties of undefined (reading 'place_id')
    at Object.getOptionValue (http://localhost:3000/static/js/bundle.js:286026:24)
    at Cr (http://localhost:3000/static/js/bundle.js:284243:14)
    at http://localhost:3000/static/js/bundle.js:284253:12
    at Array.some (<anonymous>)
    at xr (http://localhost:3000/static/js/bundle.js:284252:12)
    at mr (http://localhost:3000/static/js/bundle.js:284194:17)
    at http://localhost:3000/static/js/bundle.js:284215:13
    at Array.map (<anonymous>)
    at Ir (http://localhost:3000/static/js/bundle.js:284201:20)
    at http://localhost:3000/static/js/bundle.js:285290:25

Annotation 2023-06-23 172142

<AsyncSelect
      {...args.selectProps ?? {}}
      loadOptions={fetchSuggestions}
      getOptionValue={({ value }) => value.place_id} // Here is the error while accessing 'place_id'
/>

It seems that when rendering the component dynamically, the 'place_id' property becomes inaccessible. This issue needs to be investigated and resolved to ensure the component functions correctly in all scenarios.

Steps to Reproduce:

Render the component dynamically, such as by mapping it with an array and adding an extra item to the array. Check the browser console for the error message mentioned above.

Tintef commented 2 months ago

@Shaxadhere Can you please provide a repo/codesandbox and steps to reproduce? thanks