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.
sdk.reviews.methods.getReviewsStateKit()getReviewsStateKit(): Promise<ErrorResult | SuccessResult<ReviewsStateKit>>Returns
Promise<ErrorResult | SuccessResult<ReviewsStateKit>>Promise resolving to a state kit with query and service methods for reactive reviews 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
ReviewsStateKitProperties
readonly queryReviewsStateKitQueryWrapperreadonly serviceReviewsStateKitServiceWrapper
ReviewsStateKitQueryWrapper
ReviewsStateKitQueryWrapperMethods
selectAll()Observable<ReviewItemSdkDto[]>selectEntity(uid)Observable<ReviewItemSdkDto | undefined>selectFirst()Observable<ReviewItemSdkDto | undefined>selectPaginationMeta()Observable<ReviewsPaginationMetaSdkDto>
Returns:
Parameters
| Name | Type | Description |
|---|---|---|
| uid | string | — |
Returns:
Observable<ReviewItemSdkDto | undefined>
Returns:
Observable<ReviewItemSdkDto | undefined>
Returns:
ReviewsStateKitServiceWrapper
ReviewsStateKitServiceWrapperMethods
getReviews(params?)Observable<ReviewsSdkDto>- Retrieves reviews with optional filtering. Replaces the current store contents.
loadMoreReviews(params)Observable<ReviewsSdkDto>- Retrieves additional reviews and appends them to the store. Ideal for infinite scroll or "load more" pagination.
Parameters
| Name | Type | Description |
|---|---|---|
| params? | GetReviewsParamsSdkDto | (Optional) Filtering parameters |
Parameters
| Name | Type | Description |
|---|---|---|
| params | GetReviewsParamsSdkDto | Must include the same filters as the initial `getReviews` call, with an updated `offset` param |
Returns:
Observable emitting the complete reviews collection, including newly loaded items.
ReviewItemSdkDto
ReviewItemSdkDtoProperties
bodystring- Review text
createdAtstring- Date the review was created
customerReviewItemCustomerSdkDto | null- Review author, or
nullif 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
nullfor a shop review ratingnumber- Rating from 1 to 5
replyReviewItemReplySdkDto | null- Merchant reply, or
nullif there is none shopNamestring- Name of the shop
titlestring | null- Review title, or
nullif not provided uidstring- Unique identifier for state management
votesnumber- Number of helpful votes