@sskmy1024y/trpc-swr-infinite
TypeScript icon, indicating that this package has built-in type declarations

1.0.3-beta.0 • Public • Published

@trpc-swr/infinite

tRPC-ified SWR hooks

Documentation: https://trpc-swr.vercel.app/infinite-queries

// profile.tsx
const { data, error, size, setSize } = infinite.user.getMany.useCursor(
  { limit: 3 },
  (index, previousPageData) => {
    return previousPageData?.nextCursor;
  }
);

const users = data?.pages.flat() || [];
const hasMore = data?.at(-1).nextCursor !== null;

return (
  <div>
    {users.map((user) => (
      <div key={user.id}>{user.name}</div>
    ))}
    {hasMore && (
      <button
        onClick={() => {
          setSize(size + 1);
        }}
      >
        Load more
      </button>
    )}
  </div>
);

Readme

Keywords

none

Package Sidebar

Install

npm i @sskmy1024y/trpc-swr-infinite

Weekly Downloads

2

Version

1.0.3-beta.0

License

MIT

Unpacked Size

25.7 kB

Total Files

12

Last publish

Collaborators

  • sskmy1024y