getSuggestions(query: string): Promise<string[] | null>¶
The getSuggestions is an asynchronous method that allows you to get the search suggestions based on a given query.
Input parameters¶
query¶
query is a mandatory parameter of string type which represents a query to which suggestions should be returned.
Returned value¶
A returned value is has a type of Promise<string[] | undefined> where string[] represents a list of suggestions for a query.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- FlashMessengerApi.addFlashMessages - when handling messages that come from a server
Example¶
In this example we make a SearchApi call to get suggestions based on a given query.
useStorefront(async (storefront) => {
const searchApi = await storefront.getApi('SearchApi');
const suggestions = await searchApi.getSuggestions('black shirt');
});