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

Wait before sending AJAX call #384

Closed
radar opened this issue Aug 17, 2015 · 6 comments
Closed

Wait before sending AJAX call #384

radar opened this issue Aug 17, 2015 · 6 comments

Comments

@radar
Copy link

radar commented Aug 17, 2015

How can I get react-select to wait for someone to stop typing before making an async call so that I don't get calls like this?

image

@janmyler
Copy link

Hi @radar, in our project, we use throttle or debounce methods from lodash to wrap the function we pass into asyncOptions prop.

If you want to wait for the user to stop typing for a certain amount of time, debounce is what you're looking for. Of course, any implementation of debouncing will do.

@radar
Copy link
Author

radar commented Aug 18, 2015

Wonderful, thank you @janmyler!

@radar radar closed this as completed Aug 18, 2015
@rescribet
Copy link

For people not wanting to use external libraries for this, a simple timeout also does the trick:

window.clearTimeout(this.currentFetchTimeout);
this.currentFetchTimeout = window.setTimeout(() => {
          // Do some fetching and call callback();
});

@vgoklani
Copy link

Hi @janmyler could you please post a good snippet for how you implemented throttle/debounce with react-select? Thanks! It's not clear how to bind the input/callback with the debounced function?

@marcelometal
Copy link

You can use es6-promise-debounce.

<Select.Async
...
loadOptions={debounce(this.getItem, 500)}
... />

@mikdatdogru
Copy link

thanks @marcelometal

perhaps you may be afraid to use a package that does not actively develop like me.
so you can use the lodash.

import _ from 'lodash';

 <Select.Async
    ...
    loadOptions={_.debounce(this.getItem, 500)}
    ...
/>

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

No branches or pull requests

6 participants