--- title: getPaginationVariables description: >- The `getPaginationVariables` function is used with the [``](/docs/api/hydrogen/components/pagnination) component to generate the variables needed to fetch paginated data from the Storefront API. The returned variables should be used within your storefront GraphQL query. api_version: 2024-01 api_name: hydrogen source_url: html: >- https://shopify.dev/docs/api/hydrogen/2024-01/utilities/getpaginationvariables md: >- https://shopify.dev/docs/api/hydrogen/2024-01/utilities/getpaginationvariables.md --- # get​Pagination​Variables The `getPaginationVariables` function is used with the [``](https://shopify.dev/docs/api/hydrogen/components/pagnination) component to generate the variables needed to fetch paginated data from the Storefront API. The returned variables should be used within your storefront GraphQL query. ## get​Pagination​Variables([request](#props-propertydetail-request)​,[options](#props-propertydetail-options)​) ### Parameters * request Request required The request object passed to your Remix loader function. * options { pageBy: number; } Default: {pageBy: 20} Options for how to configure the pagination variables. Includes the ability to change how many nodes are within each page. ### Examples * #### Example code ##### Description I am the default example ##### JavaScript ```jsx import {json} from '@shopify/remix-oxygen'; import {Pagination, getPaginationVariables} from '@shopify/hydrogen'; import {useLoaderData, Link} from '@remix-run/react'; export async function loader({request, context: {storefront}}) { const variables = getPaginationVariables(request, {pageBy: 8}); const data = await storefront.query(ALL_PRODUCTS_QUERY, { variables, }); return json({products: data.products}); } export default function List() { const {products} = useLoaderData(); return ( {({nodes, PreviousLink, NextLink}) => ( <> Previous
{nodes.map((product) => ( {product.title} ))}
Next )}
); } const ALL_PRODUCTS_QUERY = `#graphql query AllProducts( $country: CountryCode $language: LanguageCode $first: Int $last: Int $startCursor: String $endCursor: String ) @inContext(country: $country, language: $language) { products(first: $first, last: $last, before: $startCursor, after: $endCursor) { nodes { id title handle } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } } } `; ``` ##### TypeScript ```tsx import {json, type LoaderFunctionArgs} from '@shopify/remix-oxygen'; import {Pagination, getPaginationVariables} from '@shopify/hydrogen'; import {useLoaderData, Link} from '@remix-run/react'; import {ProductConnection} from '@shopify/hydrogen/storefront-api-types'; export async function loader({ request, context: {storefront}, }: LoaderFunctionArgs) { const variables = getPaginationVariables(request, {pageBy: 8}); const data = await storefront.query<{products: ProductConnection}>( ALL_PRODUCTS_QUERY, { variables, }, ); return json({products: data.products}); } export default function List() { const {products} = useLoaderData(); return ( {({nodes, NextLink, PreviousLink}) => ( <> Previous
{nodes.map((product) => ( {product.title} ))}
Next )}
); } const ALL_PRODUCTS_QUERY = `#graphql query AllProducts( $country: CountryCode $language: LanguageCode $first: Int $last: Int $startCursor: String $endCursor: String ) @inContext(country: $country, language: $language) { products(first: $first, last: $last, before: $startCursor, after: $endCursor) { nodes { id title handle } pageInfo { hasPreviousPage hasNextPage startCursor endCursor } } } `; ``` ## Related [- Pagination](https://shopify.dev/docs/api/hydrogen/2024-01/components/pagination)