# getPaginationVariables > Caution: > This component is in an unstable pre-release state and may have breaking changes in a future release. 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. ```jsx import {json} from '@shopify/remix-oxygen'; import { Pagination__unstable as Pagination, getPaginationVariables__unstable as 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 } } } `; ``` ```tsx import {json, type LoaderArgs} from '@shopify/remix-oxygen'; import { Pagination__unstable as Pagination, getPaginationVariables__unstable as 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}}: LoaderArgs) { 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 } } } `; ``` ## Props ### GetPaginationVariablesGeneratedType #### Returns: Variables to be used with the `storefront.query` function #### Params: - request: Request - options: { pageBy: number; } export function getPaginationVariables( request: Request, options: {pageBy: number} = {pageBy: 20}, ) { if (!(request instanceof Request)) { throw new Error( 'getPaginationVariables must be called with the Request object passed to your loader function', ); } const {pageBy} = options; const searchParams = new URLSearchParams(new URL(request.url).search); const cursor = searchParams.get('cursor') ?? undefined; const direction = searchParams.get('direction') === 'previous' ? 'previous' : 'next'; const isPrevious = direction === 'previous'; const prevPage = { last: pageBy, startCursor: cursor ?? null, }; const nextPage = { first: pageBy, endCursor: cursor ?? null, }; const variables = isPrevious ? prevPage : nextPage; return variables; } ## Related - [Pagination](https://shopify.dev/docs/api/hydrogen/2023-04/components/pagination)