Pro (paid add-on)
Reviews
ProReviewsSection is everything below a product's description: the rating summary, sorting and filters, the review list with pages, and a "Write a review" button that opens ReviewForm in a modal. Built from the free [ReviewCard](/docs/components/review-card) and [RatingBreakdown](/docs/components/rating-breakdown).
Part of Pro
This page documents part of @vjdesigns-pro/ui, the paid add-on package. Using it needs a Pro license and @vjdesigns/vjdesigns-ui 3.8.0 or later. Like the free package, it works in both modes, every brand, all 32 languages and right to left. Install it as described in Account forms.
Example
Pass the reviews and the count per star level. The summary's rows filter the list by level, and the section adds sorting, "with photos" and "verified" filters, and pages. Put a ReviewForm in reviewForm and the "Write a review" button opens it in a modal.
import { ReviewForm, ReviewsSection } from "@vjdesigns-pro/ui";
<ReviewsSection
title="Customer reviews"
reviews={reviews}
counts={{ 5: 920, 4: 210, 3: 80, 2: 40, 1: 34 }}
recommendPercent={92}
onHelpfulChange={voteHelpful}
reviewForm={<ReviewForm title={null} description="Pro Grip basketball shoes" onSubmit={postReview} />}
/>
The review form
ReviewForm asks for a star rating (required), "would you recommend it?", a headline, photos, a "post anonymously" switch, and the review text with a minimum length and a character count. onSubmit sends it to your backend; return an error to show it, and the form shows a thank-you message once it's posted. Turn optional parts off with fields, for example fields={{ photos: false }}.
async function postReview(values: ReviewValues) {
const response = await fetch("/api/reviews", { method: "POST", body: toFormData(values) });
if (!response.ok) return { error: "We couldn't post your review. Please try again." };
}
Large review lists
Without pageCount, the section sorts, filters and pages the reviews you pass, in the browser. For long lists, page on your server: control the query (sort, level, filters and page), fetch the matching reviews in onQueryChange, and pass pageCount and totalResults. applyReviewsQuery() does the same filtering and sorting, if you want it on your server.
<ReviewsSection
reviews={page.reviews}
counts={summary.counts}
query={query}
onQueryChange={setQuery} // fetch the matching page here
pageCount={page.pageCount}
totalResults={page.total}
loading={loading}
/>
Accessible by default
- Each review is an
<article>named by its headline, and headings follow the section'sheadingLevel. - "Showing 24 reviews" is a status message, so filter changes are announced, and changing pages moves focus to the top of the list.
- The rating filters are toggle buttons with
aria-pressed, and the form opens in a modal dialog that keeps focus inside. - The form lists problems in an error summary, and a server error takes focus so it's read right away.
Props
ReviewForm
A ready-made "write a review" form: a required star rating, optional "would you recommend it?" thumbs and headline, the review text (with a minimum length and a character count), optional photos, and a "post anonymously" switch. Validates on submit with an error summary, focuses the first problem, and shows server errors from onSubmit.
| Prop | Type | Default |
|---|---|---|
onSubmitRequiredCalls your backend with the review. See | (values: ReviewValues) => ReviewSubmitResult | Promise<ReviewSubmitResult> | — |
onSuccessCalled after | (values: ReviewValues) => void | — |
titleHeading. Pass | ReactNode | "Write a review" |
descriptionText under the heading, e.g. the product name. | ReactNode | — |
headingLevelHeading level. | 123456 | 2 |
defaultValuesPrefilled values, e.g. when editing a review. | Partial<Omit<ReviewValues, "photos">> | — |
maxRatingHighest star rating. | number | 5 |
minBodyLengthShortest review text accepted, in characters. | number | 50 |
maxBodyLengthLongest review text accepted, in characters. | number | 5000 |
maxPhotosMost photos one review can attach. | number | 5 |
fieldsTurn optional parts off. | ReviewFormFields | — |
submitLabelSubmit button text. | ReactNode | "Post review" |
successContentShown in place of the form after a successful submit. | ReactNode | a "Thanks" message |
variant
| "card""plain" | "card" |
classNameClass name for the | string | — |
styleStyle for the | CSSProperties | — |
ReviewsSection
A complete reviews section: the rating summary (whose rows filter by star level), sorting, "with photos" and "verified" filters, the review list, pagination, and a "Write a review" modal. Works on a full list in the browser, or on server pages through query / onQueryChange and pageCount.
| Prop | Type | Default |
|---|---|---|
reviewsRequiredReviews to show. Without | readonly ReviewItem[] | — |
countsRequiredReviews per star level, for the summary. | Record<number, number> | — |
averageAverage rating. Computed from | number | — |
recommendPercentShare who would recommend, 0 to 100. | number | — |
maxHighest star rating. | number | 5 |
queryThe sort, filters, and page (controlled). | ReviewsQuery | — |
defaultQueryInitial query (uncontrolled). | Partial<ReviewsQuery> | most recent, no filters, page 1 |
onQueryChangeCalled with the new query when the viewer sorts, filters, or pages. Fetch the matching reviews here. | (query: ReviewsQuery) => void | — |
pageCountServer mode: total pages for the current query. Omit to filter and page | number | — |
totalResultsServer mode: how many reviews match the query, for "Showing 24 reviews". | number | — |
pageSizeBrowser mode: reviews per page. | number | 10 |
onHelpfulChangeCalled when the viewer votes a review helpful or not. | (id: string, helpful: boolean | null) => void | — |
reviewFormThe form to show when the viewer presses "Write a review", usually a | ReactNode | — |
formOpenOpen state of the write-a-review modal (controlled), e.g. to close it after a successful submit. | boolean | — |
onFormOpenChangeCalled when the write-a-review modal opens or closes. | (open: boolean) => void | — |
titleHeading. | ReactNode | "Reviews" |
headingLevelHeading level; each review's headline uses the next level. | 2345 | 2 |
loadingShows the list as busy (e.g. while fetching a page). | boolean | — |
classNameClass name for the | string | — |
styleStyle for the | CSSProperties | — |
ReviewValues
What ReviewForm sends to onSubmit.
| Prop | Type | Default |
|---|---|---|
ratingRequiredStar rating, 1 to | number | — |
recommendRequired"Would you recommend it?": | boolean | null | — |
titleRequiredHeadline; empty when skipped (or hidden). | string | — |
bodyRequiredThe review text. | string | — |
photosRequiredAttached photos (empty when photos are off). | File[] | — |
anonymousRequired"Post anonymously" was on. | boolean | — |
ReviewSubmitResult
What a ReviewForm onSubmit handler returns. Return nothing when it worked. Return error for one message above the form, and/or fieldErrors for messages on fields by name (rating, recommend, title, body, photos). If the handler throws, a generic message shows.
| Prop | Type | Default |
|---|---|---|
error | ReactNode | — |
fieldErrors | FormErrors | — |
ReviewFormFields
Optional parts of ReviewForm that can be turned off.
| Prop | Type | Default |
|---|---|---|
recommend"Would you recommend it?" thumbs. | boolean | true |
titleHeadline input. | boolean | true |
photosPhoto upload. | boolean | true |
anonymous"Post anonymously" switch. | boolean | true |
ReviewItem
One review in a ReviewsSection.
| Prop | Type | Default |
|---|---|---|
idRequiredUnique id. | string | — |
authorRequired | ReviewAuthor | — |
rating | number | — |
title | ReactNode | — |
dateISO date ("YYYY-MM-DD"). Used for "Most recent" sorting. | string | — |
verified | boolean | — |
recommend | boolean | — |
bodyRequiredThe review text. | ReactNode | — |
mediaPhotos. A review with | ReactNode | — |
helpfulCount | number | — |
helpfulThe viewer's helpful vote, if any. | boolean | null | — |
response | ReviewResponse | — |
ReviewsQuery
The section's sort, filters, and page.
| Prop | Type | Default |
|---|---|---|
sortRequired | "recent""highest""lowest""helpful" | — |
levelRequiredShow only this star level, or all ( | number | null | — |
withPhotosRequiredOnly reviews with photos. | boolean | — |
verifiedRequiredOnly verified reviews. | boolean | — |
pageRequired1-based page. | number | — |