Skip to content

selectHasBeenReviewed$(productId: string): Observable<boolean>

The selectHasBeenReviewed$ method returns an observable with the information about whether the product with a given ID has been reviewed before from the local storage.

Input parameters

productId

string represents the ID of the product to check.

Returned value

A returned value has a type of Observable<boolean>. If a given product has been reviewed before the returned value will be true. If none of these actions have been performed in the past it will be false.

Example

In this example we make a RateAndReviewApi call to check whether a given product has been reviewed before.

useStorefront((storefront) => {
    const rateAndReviewApi = await storefront.getApi('rateAndReviewApi');

    const hasBeenReviewed$ = rateAndReviewApi.selectHasBeenReviewed$("145");

    hasBeenReviewed$.subscribe((hasBeenReviewed) => {
        if (hasBeenReviewed) {
            // do something if product has been reviewed 
        }

        if (!hasBeenReviewed) {
            // do something if product has not been reviewed
        }
    });
});

Rate And Review API methods reference