1

I'm building a react-native app where i use react-native-maps package to show markers on the map with every region by sending request to my server to get some data

<MapView
        followUserLocation
        initialRegion={region}
        ref={(ref) => { this.mapRef = ref; }}
        showsUserLocation
        style={styles.map}
        onRegionChange={this.onRegionChange.bind(this)}
/>

on RegionChange i send a request to my server

onRegionChange(region) {
// send my request to my server
}

but the user may make many region change in a very short time , how can i make sure that i'll get the correct response (i.e response related to the last region change ) ??

1 Answer 1

1

There are several ways to achieve this.

Debounce

Use debounce for "onRegionChange". This way only the last change will be executed.

More info: Perform debounce in React.js

Cancelable promises

Some Promise libraries provide cancelable promises.

More info: http://bluebirdjs.com/docs/api/cancel.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.