React-native-google-places-autocomplete: Can't call setState (or forceUpdate) on an unmounted component.

Created on 1 Sep 2018  路  4Comments  路  Source: FaridSafi/react-native-google-places-autocomplete

Error:

Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

Description:

Pressing on a "Place" item in the listview from react-native-google-places-autocomplete triggers the error. I've stepped through it in Chrome's devtools and found the error occurs right after TouchableHighlight from _renderRow (please see screenshot below).

screen shot 2018-08-31 at 7 40 47 pm

Code:

  <GooglePlacesAutocomplete
    autoFocus
    debounce={200}
    enablePoweredByContainer={false}
    fetchDetails={false}
    GooglePlacesSearchQuery={{
      rankby: 'distance',
      types: 'establishment'
    }}
    listViewDisplayed={destinationInput}
    minLength={2}
    nearByPlacesAPI="GooglePlacesSearch"
    onPress={data => setDestination(data)}
    placeholder="Where to?"
    placeholderTextColor="black"
    ref={setRef}
    returnKeyType="search"
    styles={searchDestStyle}
    textInputProps={{
      onBlur: blurDest,
      onFocus: focusDest
    }}
    query={{
      key: config.apiKey,
      language: 'en',
      types: ['establishment', 'geocode'],
      location: '37.786279,-122.406456',
      radius: '15000',
      components: 'country:us'
    }}
  />

destinationInput is a Boolean from redux state.
setDestination, blurDest, focusDest are a redux action creators.
setDestination sends the location data to redux state, which react-native-maps-directions uses to send direction coordinates to react-native-maps. Then a react-native modal is triggered.

Relevant dependencies:

    "expo": "^29.0.0",
    "react": "16.4.2",
    "react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
    "react-native-google-places-autocomplete": "^1.3.9"

Most helpful comment

set debounce to 0 if it is fine with your usecase.

All 4 comments

Same here! But I just get a warning.

set debounce to 0 if it is fine with your usecase.

I have the same problem and setting debounce to 0 didn't help. The warning is still there half of the times.

This sounds like it might be caused by redux updating the props when the component is unmounted, hence the error. See this article for more.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nikohosn picture nikohosn  路  3Comments

sohel-tech picture sohel-tech  路  3Comments

tgreco picture tgreco  路  3Comments

DennisMuchiri picture DennisMuchiri  路  4Comments

RajanPN picture RajanPN  路  3Comments