Skip to content

Add reset function to useAlgoliaSearch() #201

@MickL

Description

@MickL

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:

const searchInput = ref('');
const { result, search, reset } = useAlgoliaSearch('products');

watchDebounced(
  searchInput,
  async () => {
    if (searchInput.length < 4) {
         reset();
         return;
    }

    await search({
      query: searchInput.value,
    });
  },
  { debounce: 200, maxWait: 500 },
);

onUnmounted(() => {
  reset();
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions