PostgREST
Custom Cache Updates

Custom Cache Updates

Sometimes, you will find yourself writing custom cache updates. The library exports two convenience hooks that expose the underlying cache operations.

useDeleteItem

Delete a postgrest entity from the cache. Note that you have to pass a value for all primary keys in the input.

import { useDeleteItem } from "@supabase-cache-helpers/postgrest-swr";
 
function Page() {
    const deleteItem = useDeleteItem({
      primaryKeys: ['id'],
      table: 'contact',
      schema: 'public',
      opts,
    });
 
  return <div>...</div>;
}

useUpsertItem

Upsert a postgrest entity into the cache. Note that you have to pass a value for all primary keys in the input.

import { useUpsertItem } from "@supabase-cache-helpers/postgrest-swr";
 
function Page() {
    const deleteItem = useDeleteItem({
      primaryKeys: ['id'],
      table: 'contact',
      schema: 'public',
      opts,
    });
 
  return <div>...</div>;
}