search(query: string): Promise<TSearchResponse | null>¶
The search
is an asynchronous method that allows you to search for all items (products, producers, categories) based on a given query.
Input parameters¶
query¶
query
is a mandatory parameter of string
type which represents a query to which results should be returned.
Returned value¶
A returned value is has a type of Promise<TSearchResponse[] | undefined>
. You can read more about TSearchResponse here.
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 search results based on a given query.
useStorefront(async (storefront) => {
const searchApi = storefront.getApiSync('SearchApi');
const searchResults = await searchApi.search('Samsung');
});