React-select: Option to wait before sending queries for asyncOptions

Created on 19 Sep 2015  路  6Comments  路  Source: JedWatson/react-select

It would be nice if we could specify a time delay to wait after the last keystroke before calling asyncOptions, so it doesn't make unnecessary requests.

Most helpful comment

For those who might need, for now you can have debouncing by wrapping your loadOptions callback by lodash/debounce

const wait = 500; // milliseconds
const loadOptions = input => dataStore.getData(input)
const debouncedLoadOptions = _.debounce(loadOptions, wait)

return <Async loadOptions={debouncedLoadOptions} ... />

All 6 comments

Bump, as far as I can see asyncOptions are fired on change, is it possible to fire it when user stops typing?

It's implemented in my branch https://github.com/JedWatson/react-select/pull/473 @PSkierniewski

@oliversong Thx I used it and it works.

@oliversong i need this too. Can you check the PR for this feature to fix it so it can be merged?

For those who might need, for now you can have debouncing by wrapping your loadOptions callback by lodash/debounce

const wait = 500; // milliseconds
const loadOptions = input => dataStore.getData(input)
const debouncedLoadOptions = _.debounce(loadOptions, wait)

return <Async loadOptions={debouncedLoadOptions} ... />

It looks like @JedWatson has expressed that this be left for users to implement in the function that's passed to loadOptions.

For those doing so, Lodash's debounce function is not suited for this. Instead, a promise-returning debounce method where subsequent calls return promises which will resolve to the result of the next func invocation in needed. See https://github.com/JedWatson/react-select/issues/3075#issuecomment-450194917

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MindRave picture MindRave  路  3Comments

Meesam picture Meesam  路  3Comments

pgoldweic picture pgoldweic  路  3Comments

batusai513 picture batusai513  路  3Comments

geraldfullam picture geraldfullam  路  3Comments