-
-
Save scottdixon/7a7c5ea5192615d96ea8de0111d1e4e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import {Pagination} from '@shopify/hydrogen'; | |
/** | |
* <PaginatedResourceSection > is a component that encapsulate how the previous and next behaviors throughout your application. | |
*/ | |
export function PaginatedResourceSection<NodesType>({ | |
connection, | |
children, | |
resourcesClassName, | |
namespace, | |
}: { | |
connection: React.ComponentProps<typeof Pagination<NodesType>>['connection']; | |
children: React.FunctionComponent<{node: NodesType; index: number}>; | |
resourcesClassName?: string; | |
namespace?: string; | |
}) { | |
return ( | |
<Pagination connection={connection} namespace={namespace}> | |
{({nodes, isLoading, PreviousLink, NextLink}) => { | |
const resoucesMarkup = nodes.map((node, index) => | |
children({node, index}), | |
); | |
return ( | |
<div> | |
<PreviousLink> | |
{isLoading ? 'Loading...' : <span>↑ Load previous</span>} | |
</PreviousLink> | |
{resourcesClassName ? ( | |
<div className={resourcesClassName}>{resoucesMarkup}</div> | |
) : ( | |
resoucesMarkup | |
)} | |
<NextLink> | |
{isLoading ? 'Loading...' : <span>Load more ↓</span>} | |
</NextLink> | |
</div> | |
); | |
}} | |
</Pagination> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment