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

feat: add infinite query example #69

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

kroucher
Copy link

This PR adds an additional sample to the kitchen sink collection, utilizing the infinite query procedure.

The Reddit /r/Aww subreddit is used as the API endpoint, which returns a cursor in the form of an after property.

There is basic styling to show similarities to a Reddit post, and a native intersection observer to call the fetchNextPage function. More than happy to make any changes to code or styling as requested.

Screenshots

Homepage

image

Infinite Query Page - Initial Loading State

image

Infinite Query Page - Content loaded

image

@vercel
Copy link

vercel bot commented Sep 29, 2022

@kroucher is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

@c-ehrlich
Copy link
Collaborator

I don't like the idea of relying on an external api for something like this. Does the demo lose anything if it just uses an array of lorem ipsum sentences or something like that?

@kroucher
Copy link
Author

kroucher commented Sep 29, 2022

I don't like the idea of relying on an external api for something like this. Does the demo lose anything if it just uses an array of lorem ipsum sentences or something like that?

I understand what you mean, I was tossing up between faux data and a real API and the main reason is that I didn't want to give the wrong impression/idea about the cursor - that it should come from the external service you're interacting with (which indicates there are more results), not just generated on your backend.

If the example showed a cursor being generated and passed through, I fear people will see that and think that's how cursors work.

It was also why the Aww subreddit was chosen as the external service - if there's any external service that will always be available, it's Reddit, and if there's a subreddit that won't have any undesirable content being returned, it's the Aww subreddit :P

Copy link
Member

@KATT KATT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've completely missed this!! Thanks.

Definitely a good addition

.input(
z.object({
limit: z.number().min(1).max(100),
cursor: z.string().optional(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cursor should be validated so you can't inject anything into the url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants