-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add reset function to useAlgoliaSearch() #201
Comments
Hey there, Thanks for reporthing this feature request. I do like this idea but I wonder if maybe you could do something like this already: const searchInput = ref('');
const { result, search, reset } = useAlgoliaSearch('products');
watchDebounced(
searchInput,
async () => {
if (searchInput.length < 4) {
result.value.hits = [];
return;
}
await search({
query: searchInput.value,
});
},
{ debounce: 200, maxWait: 500 },
);
onUnmounted(() => {
result.value.hits = [];
}); You can even wrap it around with a function Let me know what you think about it :) |
Let me check! :) I would kinda expect the composable resets when the component is unmounted tho. Or maybe a new option that toggles reset onUnmounted so it is not the default but can be activated? There is also a problem that it flickers when I remove the search result when the input is empty and when it then comes again it shows the previous result for a split second. So a reset is very much required imo. I will check if I can set the hits to an empty array BUT I already have a message "No results found" when the array is empty. So it would be better if the whole result is empty again like before the first search. |
So I tried and I made a PR that should do the trick, optionally this could be done by an configurable option. |
Is your feature request related to a problem? Please describe.
When having the search in something like a popup / modal I would like the search to reset when closing it. Unfortunately even tho my search component gets unmounted, the next time it gets mounted it already shows the previous result.
Another use case is that I want to reset the search when the input is empty.
Describe the solution you'd like
Add a
useAlgoliaSearch
should return a 'reset()` function that can be called e.g. onUnmounted().Example:
The text was updated successfully, but these errors were encountered: