From 35cb22576be2dfb2761e74bb3fcc2b9f0b86d590 Mon Sep 17 00:00:00 2001 From: Max Lielje Date: Tue, 20 Jul 2021 12:43:27 +0200 Subject: [PATCH] fix: loading: disable loading correctly short circuit logic when a request comes back prevented the loading spinner from being hidden --- src/autocomplete/autocomplete.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/autocomplete/autocomplete.js b/src/autocomplete/autocomplete.js index e1525b5..9cf8658 100644 --- a/src/autocomplete/autocomplete.js +++ b/src/autocomplete/autocomplete.js @@ -47,11 +47,12 @@ export default ({ // search queries the autocomplete API const search = useCallback(text => { autocomplete(text).then(({ features, discard }) => { + setIsLoading(false) + if (discard || inputRef.current.value !== text) { return } - setIsLoading(false) setResults({ text, features }) openMenu() })