Infinite Query Hook
supabase-library/infinite-query-hookFreeBlock
React hook for infinite lists, fetching data from Supabase.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/supabase/supabase/master/apps/ui-library/public/r/infinite-query-hook.jsonSource
1'use client'23import { PostgrestQueryBuilder, type PostgrestClientOptions } from '@supabase/postgrest-js'4import { type SupabaseClient } from '@supabase/supabase-js'5import { useEffect, useMemo, useRef, useSyncExternalStore } from 'react'67import { createClient } from '@/registry/default/fixtures/lib/supabase/client'89const supabase = createClient()1011// The following types are used to make the hook type-safe. It extracts the database type from the supabase client.12type SupabaseClientType = typeof supabase1314// Utility type to check if the type is any15type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N1617// Extracts the database type from the supabase client. If the supabase client doesn't have a type, it will fallback properly.18type Database =19 SupabaseClientType extends SupabaseClient<infer U>20 ? IfAny<21 U,22 {23 public: {24 Tables: Record<string, any>25 Views: Record<string, any>26 Functions: Record<string, any>27 }28 },29 U30 >31 : {32 public: {33 Tables: Record<string, any>34 Views: Record<string, any>35 Functions: Record<string, any>36 }37 }3839// Change this to the database schema you want to use40type DatabaseSchema = Database['public']4142// Extracts the table names from the database type43type SupabaseTableName = keyof DatabaseSchema['Tables']4445// Extracts the table definition from the database type46type SupabaseTableData<T extends SupabaseTableName> = DatabaseSchema['Tables'][T]['Row']4748// Default client options for PostgrestQueryBuilder49type DefaultClientOptions = PostgrestClientOptions5051type SupabaseSelectBuilder<T extends SupabaseTableName> = ReturnType<52 PostgrestQueryBuilder<53 DefaultClientOptions,54 DatabaseSchema,55 DatabaseSchema['Tables'][T],56 T57 >['select']58>5960// A function that modifies the query. Can be used to sort, filter, etc. If .range is used, it will be overwritten.61type SupabaseQueryHandler<T extends SupabaseTableName> = (62 query: SupabaseSelectBuilder<T>63) => SupabaseSelectBuilder<T>6465interface UseInfiniteQueryProps<T extends SupabaseTableName, Query extends string = '*'> {66 // The table name to query67 tableName: T68 // The columns to select, defaults to `*`69 columns?: string70 // The number of items to fetch per page, defaults to `20`71 pageSize?: number72 // A function that modifies the query. Can be used to sort, filter, etc. If .range is used, it will be overwritten.73// … truncated
What it pulls in
npm packages
Files it writes
More from Supabase Library
All 60 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Current User Avatarcurrent-user-avatar-nuxtjs | Supabase Library | Blocks | Free | 1 dep · 3 files | |
| Current User Avatarcurrent-user-avatar-vue | Supabase Library | Blocks | Free | 1 dep · 3 files | |
| Dropzone (File Upload) for Nuxt and Supabasedropzone-nuxtjs | Supabase Library | Blocks | Free | 3 deps · 4 files | |
| Dropzone (File Upload) for Vue and Supabasedropzone-vue | Supabase Library | Blocks | Free | 3 deps · 4 files | |
| Password Based Auth flow for Nextjs and Supabasepassword-based-auth-nextjs | Supabase Library | Blocks | Free | 2 deps · 17 files | |
| Password Based Auth flow for Nuxt.js and Supabasepassword-based-auth-nuxtjs | Supabase Library | Blocks | Free | 2 deps · 12 files | |
| Password Based Auth flow for React and Supabasepassword-based-auth-react | Supabase Library | Blocks | Free | 1 dep · 5 files | |
| Password Based Auth flow for React Router and Supabasepassword-based-auth-react-router | Supabase Library | Blocks | Free | 4 deps · 11 files |
