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

fix: fixed Pagination, NextLink and PreviousLink return types #1774

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/popular-zebras-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Fixed Pagination, PreviousLink and NextLink types
16 changes: 5 additions & 11 deletions packages/hydrogen/src/pagination/Pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
useMemo,
useRef,
forwardRef,
type ReactNode,
type Ref,
type FC,
} from 'react';
import type {
Maybe,
Expand Down Expand Up @@ -49,13 +49,9 @@ interface PaginationInfo<NodesType> {
/** The paginated array of nodes. You should map over and render this array. */
nodes: Array<NodesType>;
/** The `<NextLink>` is a helper component that makes it easy to navigate to the next page of paginated data. Alternatively you can build your own `<Link>` component: `<Link to={nextPageUrl} state={state} preventScrollReset />` */
NextLink: (
props: Omit<LinkProps, 'to'> & {ref?: Ref<HTMLAnchorElement>},
) => ReactNode;
NextLink: FC<Omit<LinkProps, 'to'> & {ref?: Ref<HTMLAnchorElement>}>;
/** The `<PreviousLink>` is a helper component that makes it easy to navigate to the previous page of paginated data. Alternatively you can build your own `<Link>` component: `<Link to={previousPageUrl} state={state} preventScrollReset />` */
PreviousLink: (
props: Omit<LinkProps, 'to'> & {ref?: Ref<HTMLAnchorElement>},
) => ReactNode;
PreviousLink: FC<Omit<LinkProps, 'to'> & {ref?: Ref<HTMLAnchorElement>}>;
/** The URL to the previous page of paginated data. Use this prop to build your own `<Link>` component. */
previousPageUrl: string;
/** The URL to the next page of paginated data. Use this prop to build your own `<Link>` component. */
Expand Down Expand Up @@ -84,9 +80,7 @@ type PaginationProps<NodesType> = {
children: PaginationRenderProp<NodesType>;
};

type PaginationRenderProp<NodesType> = (
props: PaginationInfo<NodesType>,
) => ReactNode;
type PaginationRenderProp<NodesType> = FC<PaginationInfo<NodesType>>;

/**
*
Expand All @@ -102,7 +96,7 @@ export function Pagination<NodesType>({
console.warn('<Pagination> requires children to work properly');
return null;
},
}: PaginationProps<NodesType>) {
}: PaginationProps<NodesType>): ReturnType<FC> {
const transition = useNavigation();
const isLoading = transition.state === 'loading';
const {
Expand Down
Loading