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

2.0.1 • 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 @trpc-swr/infinite

Weekly Downloads

10

Version

2.0.1

License

MIT

Unpacked Size

26.1 kB

Total Files

12

Last publish

Collaborators

  • chiefkoshi