Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Pro (paid add-on)

Reviews

Pro

ReviewsSection 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.

tsx
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 }}.

ts
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.

tsx
<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's headingLevel.
  • "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.

ReviewForm props
PropTypeDefault
onSubmitRequired

Calls your backend with the review. See ReviewSubmitResult.

(values: ReviewValues) => ReviewSubmitResult | Promise<ReviewSubmitResult>—
onSuccess

Called after onSubmit succeeds, with the values sent.

(values: ReviewValues) => void—
title

Heading. Pass null for none (e.g. inside a modal that has its own title).

ReactNode"Write a review"
description

Text under the heading, e.g. the product name.

ReactNode—
headingLevel

Heading level.

1234562
defaultValues

Prefilled values, e.g. when editing a review.

Partial<Omit<ReviewValues, "photos">>—
maxRating

Highest star rating.

number5
minBodyLength

Shortest review text accepted, in characters.

number50
maxBodyLength

Longest review text accepted, in characters.

number5000
maxPhotos

Most photos one review can attach.

number5
fields

Turn optional parts off.

ReviewFormFields—
submitLabel

Submit button text.

ReactNode"Post review"
successContent

Shown in place of the form after a successful submit.

ReactNodea "Thanks" message
variant

card: a raised card. plain: no frame, to place in your own layout.

"card""plain""card"
className

Class name for the <form>.

string—
style

Style for the <form>.

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.

ReviewsSection props
PropTypeDefault
reviewsRequired

Reviews to show. Without pageCount, pass all of them: the section filters, sorts, and pages them itself. With pageCount, pass only the current page, already filtered and sorted for query by your server.

readonly ReviewItem[]—
countsRequired

Reviews per star level, for the summary.

Record<number, number>—
average

Average rating. Computed from counts when omitted.

number—
recommendPercent

Share who would recommend, 0 to 100.

number—
max

Highest star rating.

number5
query

The sort, filters, and page (controlled).

ReviewsQuery—
defaultQuery

Initial query (uncontrolled).

Partial<ReviewsQuery>most recent, no filters, page 1
onQueryChange

Called with the new query when the viewer sorts, filters, or pages. Fetch the matching reviews here.

(query: ReviewsQuery) => void—
pageCount

Server mode: total pages for the current query. Omit to filter and page reviews in the browser.

number—
totalResults

Server mode: how many reviews match the query, for "Showing 24 reviews".

number—
pageSize

Browser mode: reviews per page.

number10
onHelpfulChange

Called when the viewer votes a review helpful or not.

(id: string, helpful: boolean | null) => void—
reviewForm

The form to show when the viewer presses "Write a review", usually a ReviewForm with title={null} and variant="plain". Omit to hide the button.

ReactNode—
formOpen

Open state of the write-a-review modal (controlled), e.g. to close it after a successful submit.

boolean—
onFormOpenChange

Called when the write-a-review modal opens or closes.

(open: boolean) => void—
title

Heading.

ReactNode"Reviews"
headingLevel

Heading level; each review's headline uses the next level.

23452
loading

Shows the list as busy (e.g. while fetching a page).

boolean—
className

Class name for the <section>.

string—
style

Style for the <section>.

CSSProperties—

ReviewValues

What ReviewForm sends to onSubmit.

ReviewValues props
PropTypeDefault
ratingRequired

Star rating, 1 to maxRating.

number—
recommendRequired

"Would you recommend it?": true, false, or null when skipped (or hidden).

boolean | null—
titleRequired

Headline; empty when skipped (or hidden).

string—
bodyRequired

The review text.

string—
photosRequired

Attached 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.

ReviewSubmitResult props
PropTypeDefault
errorReactNode—
fieldErrorsFormErrors—

ReviewFormFields

Optional parts of ReviewForm that can be turned off.

ReviewFormFields props
PropTypeDefault
recommend

"Would you recommend it?" thumbs.

booleantrue
title

Headline input.

booleantrue
photos

Photo upload.

booleantrue
anonymous

"Post anonymously" switch.

booleantrue

ReviewItem

One review in a ReviewsSection.

ReviewItem props
PropTypeDefault
idRequired

Unique id.

string—
authorRequiredReviewAuthor—
ratingnumber—
titleReactNode—
date

ISO date ("YYYY-MM-DD"). Used for "Most recent" sorting.

string—
verifiedboolean—
recommendboolean—
bodyRequired

The review text.

ReactNode—
media

Photos. A review with media matches the "With photos" filter.

ReactNode—
helpfulCountnumber—
helpful

The viewer's helpful vote, if any.

boolean | null—
responseReviewResponse—

ReviewsQuery

The section's sort, filters, and page.

ReviewsQuery props
PropTypeDefault
sortRequired"recent""highest""lowest""helpful"—
levelRequired

Show only this star level, or all (null).

number | null—
withPhotosRequired

Only reviews with photos.

boolean—
verifiedRequired

Only verified reviews.

boolean—
pageRequired

1-based page.

number—