Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDU-1408: New doc usePagination #1733

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/localization/use-pagination.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: "usePagination"
createdAt: "2025-02-18T19:02:14.003z"
---

The `usePagination` hook provides the pagination links (i.e., `next`/`prev`) for navigating through search results. These links can be used with the `<link />` tag to improve SEO and user experience by indicating the relationship between pages (e.g., `rel="next"` and `rel="prev"`).

## Import

```tsx
import { usePagination } from '@faststore/sdk'
```

## Usage

The following example demonstrates how to implement a paginated navigation system using `usePagination`:

```tsx
import { usePagination } from '@faststore/sdk'

function Component () {
const totalProducts = 100 // Total number of products returned by the search query
const { next, prev } = usePagination(totalProducts)

return (
<>
{prev && (
<a href={prev.link} rel="prev">
Previous Page
</a>
)}
{next && (
<a href={next.link} rel="next">
Next Page
</a>
)}
</>
)
}
```

- `usePagination`: Generates pagination links (`next` and `prev`) based on the total number of products in the search result.
- `totalProducts`: The total number of products returned by the search query. This value is used to calculate the pagination links.
- `rel="prev"` and `rel="next"`: Help search engines understand the relationship between pages, improving SEO.

## API reference

The `usePagination` hook returns an object containing `next` and `prev` pagination links:

| Variable name | Data type | Description |
| -------- | --------------- | ------------ |
| `prev` | `{ cursor: number; link: string}` / `false` | An object containing the cursor position and link for the previous page of the search result. If there is no previous page, this value will be `false`. Example: `{ cursor: 10, link: '/search?page=10' }`. |
| `next` | `{ cursor: number; link: string}` / `false` | An object containing the cursor position and link for the next page of the search result. If there is no next page, this value will be `false`. Example: `{ cursor: 20, link: '/search?page=20' }`. |
Loading