Skip to main content

getReviewsStateKit

Retrieves a reactive state kit for advanced reviews management with Observable streams. Provides real-time updates and direct store access for complex UI requirements.

info

Learn more about the StateKit guide for working with reactive state management.

warning

Each call returns a new state kit instance with its own store. Save the returned state kit and reuse it across your application to maintain consistent state.

Usage examples​

Query Methods - Reactive data access​

function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.REVIEWS;
window.gw.sdk.runIfModuleReady(moduleName, () => {
window.gw.sdk.reviews.methods.getReviewsStateKit()
.then((response) => {
const { query } = response.result;

// Subscribe to all reviews in the store
query.selectAll().subscribe((reviews) => {
console.log('All reviews:', reviews);
});

// Subscribe to a specific review by UID
query.selectEntity('review-uid-123').subscribe((review) => {
console.log('Single review:', review);
});

// Subscribe to the first review
query.selectFirst().subscribe((review) => {
console.log('First review:', review);
});

// Subscribe to pagination metadata
query.selectPaginationMeta().subscribe((meta) => {
console.log('Total reviews:', meta.totalCount);
console.log('Per page:', meta.perPage);
console.log('Current offset:', meta.currentOffset);
});
})
.catch(console.error);
});
}

if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}

Service Methods - Fetch and manage reviews​

function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.REVIEWS;
window.gw.sdk.runIfModuleReady(moduleName, () => {
window.gw.sdk.reviews.methods.getReviewsStateKit()
.then((response) => {
const { service, query } = response.result;

// Fetch reviews with filters (replaces store)
service.getReviews({
productId: 123,
onlyWithPhotos: true,
perPage: 10
}).subscribe((data) => {
console.log('Filtered reviews:', data.items);
console.log('Total:', data.totalCount);
});

// Load more reviews (appends to store)
// Pass same filters with updated offset
service.loadMoreReviews({
productId: 123,
onlyWithPhotos: true,
perPage: 10,
offset: 10
}).subscribe((data) => {
console.log('All reviews including new:', data.items);
});

// Reactive updates after service calls
query.selectAll().subscribe((reviews) => {
console.log('Store updated:', reviews.length);
});
})
.catch(console.error);
});
}

if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}

Types​

ReviewsStateKit​

ReviewsStateKitQueryWrapper​

ReviewsStateKitQueryWrapper
interface
Methods
selectAll()Observable<ReviewItemSdkDto[]>
Returns:
Observable<ReviewItemSdkDto[]>
selectEntity(uid)Observable<ReviewItemSdkDto | undefined>
Parameters
NameTypeDescription
uidstring—
Returns:
Observable<ReviewItemSdkDto | undefined>
selectFirst()Observable<ReviewItemSdkDto | undefined>
Returns:
Observable<ReviewItemSdkDto | undefined>
selectPaginationMeta()Observable<ReviewsPaginationMetaSdkDto>
Returns:

ReviewsStateKitServiceWrapper​

ReviewsStateKitServiceWrapper
interface
Methods
getReviews(params?)Observable<ReviewsSdkDto>
Retrieves reviews with optional filtering. Replaces the current store contents.
Parameters
NameTypeDescription
params?GetReviewsParamsSdkDto(Optional) Filtering parameters
Returns:
Observable<ReviewsSdkDto>
Observable emitting the reviews collection.
loadMoreReviews(params)Observable<ReviewsSdkDto>
Retrieves additional reviews and appends them to the store. Ideal for infinite scroll or "load more" pagination.
Parameters
NameTypeDescription
paramsGetReviewsParamsSdkDtoMust include the same filters as the initial `getReviews` call, with an updated `offset` param
Returns:
Observable<ReviewsSdkDto>
Observable emitting the complete reviews collection, including newly loaded items.

ReviewItemSdkDto​

ReviewItemSdkDto
interface
Properties
bodystring
Review text
createdAtstring
Date the review was created
customerReviewItemCustomerSdkDto | null
Review author, or null if not available
idnumber
Review ID
imagesReviewItemImageSdkDto[]
Images attached to the review
isCustomerAuthorboolean
Whether the current customer is the author of the review
isCustomerVotedboolean
Whether the current customer has voted for the review
isIncentivizedboolean
Whether the author received a reward for the review
isPinnedboolean
Whether the review is pinned by the merchant
isPublishedboolean
Whether the review is published and visible in the storefront
productReviewItemProductSdkDto | null
Reviewed product, or null for a shop review
ratingnumber
Rating from 1 to 5
replyReviewItemReplySdkDto | null
Merchant reply, or null if there is none
shopNamestring
Name of the shop
titlestring | null
Review title, or null if not provided
uidstring
Unique identifier for state management
votesnumber
Number of helpful votes