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

Wrong return type on useDatxInfinite #1176

Closed
doroz0 opened this issue Apr 27, 2023 · 0 comments · Fixed by #1188
Closed

Wrong return type on useDatxInfinite #1176

doroz0 opened this issue Apr 27, 2023 · 0 comments · Fixed by #1188

Comments

@doroz0
Copy link

doroz0 commented Apr 27, 2023

Used libraries

core, jsonapi, swr

Library version(s)

@datx/core 2.5.1, @datx/jsonapi 2.5.1, @datx/swr 2.5.1

Sample API response (if relevant)

No response

Environments with the issue

All

Environments without the issue

No response

Current behavior

const getPostComentsRelationshipPageQuery = (id?: string, index = 1, size = 4) =>
  id
    ? ({
        id,
        op: "getRelatedResources",
        type: `posts`,
        relation: "comments",
        queryParams: {
          sort: "-created",
          include: "post",
          fields: {
            posts: "id",
          },
          custom: [
            { key: "page[number]", value: String(index) },
            { key: "page[size]", value: String(size) },
          ],
        },
      } as const satisfies IGetRelatedResourcesExpression<typeof Post>)
    : null;
  const getKey = (pageIndex: number, previousPageData: CollectionResponse | null) => {
    if (!showComments || (previousPageData && previousPageData.data.length === 0)) return null;
    return getPostComentsRelationshipPageQuery(post?.id, pageIndex + 1, 4);
  };

  const {
    data: comments, // <---------------
    mutate: mutateComments,
    size,
    setSize,
  } = useDatxInfinite(getKey, {
    revalidateAll: true,
  });

Type of comments is CollectionResponse<PostModel>[] | undefined.

Expected behavior

Type of comments is CollectionResponse<CommentModel>[] | undefined.

Reproduction steps

https://github.com/doroz0/soc-net-clone-nextjs/blob/main/src/components/Post.tsx#L38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants