Cove docs: all pages

Connect your API

Replace Cove's sample data with your own API, one screen at a time, in either edition.

Every screen reads sample data from typed TypeScript files. Connect your API one screen at a time and keep the sample data for screens you haven't connected yet.

1. Find what the screen reads

Open the screen's file and follow its imports from lib/data.ts and lib/data-ops.ts. Some table and list components import sample data themselves; note those too.

For example, the /customers screen shows Customer records. A Customer has these fields: id, name, email, plan, ltv, orders, conversations, csat, sentiment, country, lastSeen, tags.

2. Keep the kit's types

If your API returns a different shape, write one small mapping function from your shape to the kit's type instead of changing every component:

import type { Customer } from "@/lib/data-ops";

// Map one record from your API to the kit's Customer type.
export function toCustomer(api: ApiRecord): Customer {
  return {
    id: String(api.id),
    // …one line per field the screen uses
  } as Customer;
}

3. Load the data

Next.js edition

Pages are server components, so they can await data directly. Keep secrets in server environment variables.

// app/(app)/customers/page.tsx
async function getCustomers(): Promise<Customer[]> {
  const res = await fetch(`${process.env.API_URL}/customers`, { cache: "no-store" });
  if (!res.ok) throw new Error("Could not load customers");
  return res.json();
}

export default async function Page() {
  const customers = await getCustomers();
  // pass customers to the table or list component as a prop
}

Client components (files that start with "use client") can't await. Give them their data from the page instead.

React + Vite edition

Use a React Router loader, so data loads before the screen renders:

// src/routes.tsx
{ path: "customers", lazy: () => import("./pages/customers/index").then((m) => ({ Component: m.default, loader: m.loader })) },

// src/pages/customers/index.tsx
export async function loader() {
  const res = await fetch(`${import.meta.env.VITE_API_URL}/customers`);
  if (!res.ok) throw new Response("Could not load customers", { status: res.status });
  return (await res.json()) as Customer[];
}
// in the component: const customers = useLoaderData() as Customer[];

TanStack Query or SWR work too. Everything in a Vite app runs in the browser, so never put secret keys in VITE_ variables. Call your own backend, which holds the secrets.

4. Pass the data in as a prop

Give the table or list component the data as a prop instead of letting it import the sample file. Other screens keep using sample data until you connect them.

5. Handle loading, empty and error states

Use EmptyState from components/patterns/empty-state for empty and error states, and Skeleton from components/ui/misc while loading.

6. Wire up actions

Interactive pieces (approvals, toggles, bulk actions) keep their state locally and call toast(...) where a real app would call your API. Replace each of those with your API call, and keep a toast for the result, such as "Saved" or "Couldn't save: …".

See the integration guides for field mappings from common tools to the kit's types.