-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Implement rolling delay before loadAsyncOptions feature #473
Conversation
} | ||
|
||
if (this.props.asyncOptions) { | ||
var callAsyncLoad = function() { | ||
this.loadAsyncOptions(this._optionsFilterString, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick note that this._optionsFilterString
is preferable to event.target.value
, since in the case of this function it doesn't require the argument to be redefined in its closure.
any uck with this? |
@oliversong can you fix the coverage downgrade? |
Thanks for the PR @oliversong but I'd prefer this was left for users to implement in the function that's passed to You can do this really simply by wrapping the method in lodash's |
For those doing so, be aware that Lodash's debounce function isn't suitable for this. A promise-returning debounce method where subsequent calls return promises which will resolve to the result of the next func invocation in needed. See #3075 (comment) |
For those looking for a solution, please feel free to try the solution suggested here: #614 (comment) const loadOptions = React.useCallback(
debounce((inputValue, callback) => {
getOptions(inputValue).then(options => callback(options))
}, 500),
[]
);
return <AsyncSelect loadOptions={loadOptions} {...otherProps} /> Demo: codesandbox |
@ebonow take into account |
Addresses #459
Adds the ability to pass in a timeout prop. react-select will now wait
delayAsyncMs
milliseconds before calling loadAsyncOptions, and keep resetting the delay on every new input change untildelayAsyncMs
milliseconds passes without an input change.Needs tests. Sorry, didn't have time to figure that out yet, but hopefully this will be useful for somebody!