Skip to content

Commit

Permalink
Clear this._callback on cache hit
Browse files Browse the repository at this point in the history
Addresses the second issue mentioned in the linked issue. While the
previous commit makes this change unnecessary for regular use cases, the
issue is still present when debouncing. By clearing out
`this._callback`, intermediary searches (e.g. 'Ti' when 'Tim' is already
fetched) won't cause the options for 'Tim' to change when the request
for 'Ti' completes.
  • Loading branch information
Timothy Hwang committed Sep 18, 2017
1 parent d0d0396 commit 79f478e
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Async.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export default class Async extends Component {
cache &&
Object.prototype.hasOwnProperty.call(cache, inputValue)
) {
this._callback = null;

this.setState({
options: cache[inputValue]
});
Expand Down

1 comment on commit 79f478e

@YunTaoYoung
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timhwang21
Add this would be better : this.setState({ isLoading: false, options: cache[inputValue] });.
Otherwise when hitting the cache during a promise, the loading icon will remain and the menu won't appear.

Please sign in to comment.