react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Option to wait before sending queries for asyncOptions

Open oliversong opened this issue 11 years ago • 6 comments

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.

oliversong avatar Sep 18 '15 23:09 oliversong

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

PSkierniewski avatar Sep 28 '15 16:09 PSkierniewski

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

oliversong avatar Sep 30 '15 19:09 oliversong

@oliversong Thx I used it and it works.

PSkierniewski avatar Oct 01 '15 13:10 PSkierniewski

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

tommyalvarez avatar Aug 01 '17 18:08 tommyalvarez

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} ... />

duytbp avatar Aug 01 '17 21:08 duytbp

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

craigmichaelmartin avatar Dec 27 '18 17:12 craigmichaelmartin