getProduct(productId: number): Promise¶
The getProduct
is an asynchronous method that allows to fetch a single product by its id.
Input parameters¶
productId
- a number representing the product id.
Returned value¶
A returned value has a type of Promise<Product | null>
. You can read more about Product model here.
Example¶
In this example we make a ProductFetcherApi
call to get a product with id 1
.
useStorefront(async (storefront) => {
const productFetcherApi = storefront.getApiSync('ProductFetcherApi');
const product = await productFetcherApi.getProduct(1);
console.log(product);
});