Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for Maximum update depth exceeded Feature Request #916

Open
pratteekshaurya1994 opened this issue Oct 23, 2023 · 5 comments
Open

fix for Maximum update depth exceeded Feature Request #916

pratteekshaurya1994 opened this issue Oct 23, 2023 · 5 comments

Comments

@pratteekshaurya1994
Copy link

I was getting error "Maximum update depth exceeded".

So I checked you file GooglePlacesAutocomplete.js

In that I noticed in you useEffect:

useEffect(() => {
// This will load the default value's search results after the view has
// been rendered
_handleChangeText(stateText);
return () => {
_abortRequests();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [props.query]);

I think your props.query in your dependency array is causing onChangeText of textInputProps to continuously run making _handleChangeText change state continuously , I removed props.query and had an empty dependency array. then there was no issue.
Also if you give stateText then also no issue comes.

please check it, and update it accordingly

@nguyendinhdoan
Copy link

I'm having the same issue. The onChangeText is called infinitively

@nguyendinhdoan
Copy link

nguyendinhdoan commented Dec 11, 2023

I've fixed this. So instead of using:

<GooglePlacesAutocomplete
  query={{
    key: 'YOUR API KEY',
    language: 'en'
  }}
/>

I change to:

const query = useRef({
  key: 'YOUR API KEY',
  language: 'en'
}).current;

<GooglePlacesAutocomplete
  query={query}
/>

@yonitou
Copy link

yonitou commented Dec 12, 2023

@nguyendinhdoan Life savior ! It fixes the issue :)
What I did personally is that I totally removed the query variable from the component :

const query = {
  key: 'YOUR API KEY',
  language: 'en'
};

const MyComponent = (): JSX.Element => {
 return <GooglePlacesAutocomplete query={query} ... />;
}

@parnekov
Copy link

I've fixed this. So instead of using:

<GooglePlacesAutocomplete
  query={{
    key: 'YOUR API KEY',
    language: 'en'
  }}
/>

I change to:

const query = useRef({
  key: 'YOUR API KEY',
  language: 'en'
}).current;

<GooglePlacesAutocomplete
  query={query}
/>

@nguyendinhdoan Thanks! It works!

@successful-fella
Copy link

successful-fella commented Sep 14, 2024

@nguyendinhdoan Thank you so much ~

For those of you unlucky ones like me maintaining an ancient codebase, and after a routine SDK update, your client informs you next day that the app is crashing (what else is new?), you spend hours through thousands of lines of spaghetti code, only to discover—surprise!—it's GooglePlacesAutocomplete causing the havoc. Here is what you do for class component -

query = {
    key: '',
    language: 'en'
}

render() {
    return (
        ...
        <GooglePlacesAutocomplete
            ...
            query={this.query} 
        />
        ...
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants