The problem you have is that your context is bound improperly in this event handler, and this function behaves differently between contexts in JavaScript. You’ve got to have this refer correctly to the instances of your class Map, hence you need the proper binding on your functions.

Bind your function in the component’s constructor.

Change your class to include this constructor where it binds the function:

var React = require('react-native');

var {
  StyleSheet,
  Text,
  View,
  Image,
  MapView,
  Component,
} = React;

class Map extends Component {
  constructor(props) {
    super(props);
    this._onRegionChangeComplete = this._onRegionChangeComplete.bind(this);
    this._getData = this._getData.bind(this);
  }

  render() {
    return (
      <View style={styles.container}>
        <MapView style={styles.map} 
          showsUserLocation={true}
          onRegionChangeComplete={this._onRegionChangeComplete}
        />
      </View>
    );
  }

  _onRegionChangeComplete(region) {
    this._getData();  // Call the _getData function
  }

  _getData() {
    console.log("Data fetched");
  }
}

var styles = StyleSheet.create({
  container:{
    flex: 1
  },
  map: {
    flex: 1,
  },
  image: {
    width: 64,
    height: 64
  }
});

module.exports = Map;

In the constructor, this._onRegionChangeComplete and this._getData are bound to the instance of the class using.bind(this). So, when called, this would refer to the class instance.

Support On Demand!

React Native

Related Q&A