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
I am using the Autocomplete component and when onPlaceSelected I am saving the place into a state array (input) of the parent component. However, whenever a place is selected the previous value is set to an empty array and then adds the new selected place, instead of adding it to the existing array. I am thinking it has something to do with refs, but I'm not sure how to start fixing it. Any help or advice would be appreciated.
Example:
1.inputs=[place1];2.onPlaceSelected={(place2)=>{console.log(inputs);// prints empty arrayaddInput(place2);}}4.input=[place2];// should be input = [place1, place2]// addInput basically does thisfunctionaddInput(place){setInputs[...inputs,place]l;}
The text was updated successfully, but these errors were encountered:
Experiencing something similar. The onPlaceSelected encapsulates a stale version of my parent state. I'd expect the function to get updated with the latest as props change, but it remains stale.
I am using the Autocomplete component and when
onPlaceSelected
I am saving the place into a state array (input
) of the parent component. However, whenever a place is selected the previous value is set to an empty array and then adds the new selected place, instead of adding it to the existing array. I am thinking it has something to do with refs, but I'm not sure how to start fixing it. Any help or advice would be appreciated.Example:
The text was updated successfully, but these errors were encountered: