# React Native Review List with rating summary (Pro)

> A React Native review list for iOS, Android and the web: the average rating, count and star distribution bars that filter, sorting, verified buyers, photos, seller replies, Read more, Helpful votes and paging. Accessible, animated and themeable.

# Review list Pro

Customer reviews with their summary, as Amazon and Shopify stores show them: the average in large figures, the count, and a bar per star count. Press a bar to see only those reviews, sort by newest, most helpful, highest or lowest, and read each review with its stars, verified purchase, photos, the seller's reply, Read more and Helpful. On wide screens the summary sits beside the list.

```tsx
import { ReviewList } from '@patine-ui/pro';
```

```tsx live full
import { ReviewList } from '@patine-ui/pro';

const daysAgo = (d) => new Date(Date.now() - d * 86400000);
const reviews = [
  { id: '1', author: { name: 'Maya C.' }, rating: 5, title: 'Holds heat for ages', body: 'My coffee stays warm through a whole meeting. The glaze is even nicer in person.', date: daysAgo(3), verified: true, helpfulCount: 12, images: ['https://picsum.photos/id/225/200/200'] },
  { id: '2', author: { name: 'Omer L.' }, rating: 4, title: 'Beautiful, a little heavy', body: 'Lovely mug and well made. It is heavier than I expected, which I ended up liking, but it might not suit everyone who wants something light to carry around the office all day long.', date: daysAgo(9), verified: true, variant: 'Color: Ink', helpfulCount: 4, reply: { author: 'Ouro Studio', body: 'Thanks Omer! The weight comes from the thick walls that keep the heat in.' } },
  { id: '3', author: { name: 'Dana M.' }, rating: 5, body: 'Bought two as a gift and kept one.', date: daysAgo(20) },
  { id: '4', author: { name: 'Avi R.' }, rating: 2, title: 'Chipped on arrival', body: 'The rim had a small chip. Support replaced it quickly.', date: daysAgo(34), helpfulCount: 2 },
];

export default function Example() {
  return <ReviewList reviews={reviews} onHelpful={() => {}} onWriteReview={() => {}} style={{ width: '100%' }} />;
}
```

## Example: reviews on a product page

A product page's reviews: the summary up top filters by stars, the list sorts by most helpful, and Helpful votes are kept in the page so the counts move as you press them.

```tsx live wide
import { useState } from 'react';
import { ReviewList } from '@patine-ui/pro';

const daysAgo = (d: number) => new Date(Date.now() - d * 86400000);
const START = [
  { id: '1', author: { name: 'Inés M.' }, rating: 5, title: 'Fits true to size', body: 'Ordered my usual M and it’s perfect. Softens after the first wash.', date: daysAgo(2), verified: true, helpfulCount: 14 },
  { id: '2', author: { name: 'Tom B.' }, rating: 4, title: 'Lovely fabric, long sleeves', body: 'Great shirt, but the sleeves are an inch long for me. I roll them anyway.', date: daysAgo(9), verified: true, helpfulCount: 6 },
  { id: '3', author: { name: 'Yuki T.' }, rating: 3, body: 'Colour is more beige than the photos.', date: daysAgo(15), helpfulCount: 3 },
  { id: '4', author: { name: 'Sam O.' }, rating: 5, title: 'Bought a second one', body: 'Wore it all summer. Now I have it in sand and white.', date: daysAgo(40), verified: true, helpfulCount: 9 },
];

export default function Example() {
  const [reviews, setReviews] = useState(START);
  return (
    <ReviewList
      reviews={reviews}
      sort="helpful"
      onHelpful={(review) => setReviews((all) => all.map((r) => (r.id === review.id ? { ...r, helpfulCount: (r.helpfulCount ?? 0) + 1 } : r)))}
      onWriteReview={() => {}}
      style={{ width: '100%' }}
    />
  );
}
```

## Summary from the server

The summary is worked out from `reviews`. When the list is one page of many, pass the server's figures: `summary={{ average: 4.6, total: 1284, distribution: { 5: 900, 4: 250, 3: 80, 2: 30, 1: 24 } }}`.

## Sorting, filtering and paging

`sort`, `defaultSort` and `onSortChange` control the order (`'recent'`, `'helpful'`, `'highest'`, `'lowest'`); `sortOptions` picks which are offered, `[]` hides them. `ratingFilter` and `onRatingFilterChange` control the star filter the summary bars set. `pageSize` shows that many at first with Show more reviews; with `hasMore` and `onLoadMore` it asks your server for the next page once the shown ones run out.

```tsx live full
import { ReviewList } from '@patine-ui/pro';

const names = ['Noa', 'Eli', 'Tamar', 'Yossi', 'Rina', 'Gil', 'Shira', 'Ido'];
const make = (from) => Array.from({ length: 4 }, (_, i) => ({
  id: String(from + i),
  author: { name: names[(from + i) % names.length] },
  rating: [5, 4, 5, 3, 5, 4, 2, 5][(from + i) % 8],
  body: 'Arrived quickly and looks exactly like the photos.',
  date: new Date(Date.now() - (from + i) * 2 * 86400000),
}));

export default function Example() {
  const [reviews, setReviews] = React.useState(make(0));
  const [loading, setLoading] = React.useState(false);
  return (
    <ReviewList
      reviews={reviews}
      summary={{ average: 4.4, total: 12 }}
      variant="cards"
      dateFormat="relative"
      sortOptions={['recent', 'highest', 'lowest']}
      hasMore={reviews.length < 12}
      loadingMore={loading}
      onLoadMore={() => {
        setLoading(true);
        setTimeout(() => {
          setReviews((list) => [...list, ...make(list.length)]);
          setLoading(false);
        }, 700);
      }}
      style={{ width: 460 }}
    />
  );
}
```

## Helpful votes and photos

`onHelpful(review, helpful)` shows Helpful on each review; the list keeps the user's votes itself, or pass `helpful` (the ids they voted for) to control them. `onImagePress(review, index)` opens a photo, e.g. in [ImageViewer](../components/image-viewer).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `reviews` | `ReviewData[]` | — | `{ id, author: { name, avatar? }, rating, title?, body, date, verified?, helpfulCount?, images?, variant?, reply? }` |
| `variant` | `'list'` \| `'cards'` | `'list'` | |
| `showSummary` | `boolean` | `true` | |
| `summary` | `{ average?, total?, distribution? }` | from `reviews` | |
| `sort` / `defaultSort` / `onSortChange` | `'recent'` \| `'helpful'` \| `'highest'` \| `'lowest'` | `'recent'` | |
| `sortOptions` | `ReviewSort[]` | all four | |
| `ratingFilter` / `defaultRatingFilter` / `onRatingFilterChange` | `number \| null` | `null` | |
| `onHelpful` / `helpful` | | | Helpful votes. |
| `bodyLines` | `number` | `4` | Lines before Read more. |
| `pageSize` / `hasMore` / `loadingMore` / `onLoadMore` | | | Paging. |
| `onWriteReview` | `() => void` | — | Write a review, also in the empty state. |
| `onImagePress` | `(review, index) => void` | — | |
| `dateFormat` | `'date'` \| `'relative'` | `'date'` | |
| `locale` / `now` | | | |
| `renderReview` | `(info) => ReactNode` | — | |
| `loading` / `error` / `onRetry` / `emptyTitle` / `emptyDescription` / `renderEmpty` | | | States. |
| `density` / `animate` / `labels` / `design` / `theme` / `accessibilityLabel` / `style` | | | |
