Component · server or client
As-of table
Back-office questions are often about the past: what was this customer's limit when the payment went out? This table shows records as they stood at any point in time, marks every value that has changed since with the current one beside it, and labels rows that were removed.
Try it
Showing 2 Mar 2026, 23:59. Since then: 3 values changed, 1 row added, 1 row removed.
| Account | Daily limit | Signatories | Status |
|---|---|---|---|
| Northwind Supplies GmbH | €50,000.00, now €75,000.00 | 2 | Active |
| Harbor & Finch LLP | €20,000.00 | 2, now 3 | Active, now Frozen |
| Meridian Health Trust | €120,000.00 | 3 | Active |
| Orchard Foods LtdRemoved since | €12,500.00 | 1 | Active |
Step through the week. Each day shows the accounts as they stood at midnight in London, with the latest value under anything that has changed since.
Install
npx shadcn@latest add https://tellerline-ui.vercel.app/r/as-of-table.jsonThis adds the component and lib/as-of.ts. It has no state and no effects, so it renders in a server component as well as a client one.
Usage
import { AsOfTable } from "@/components/ui/as-of-table"
import { endOfDayIn } from "@/lib/as-of"
import { formatMoney } from "@/lib/money"
// Each record is its history: what was set, and when.
const accounts = [
{
id: "northwind",
history: [
{ at: "2026-02-20T10:00:00Z", set: { name: "Northwind Supplies GmbH", limit: "50000.00", status: "Active" } },
{ at: "2026-03-03T23:30:00Z", set: { limit: "75000.00" } },
],
},
]
export function Accounts({ day }: { day: string }) {
return (
<AsOfTable
caption="Corporate accounts"
records={accounts}
columns={[
{ key: "name", header: "Account" },
{ key: "limit", header: "Daily limit", align: "end", format: (v) => formatMoney(String(v), { currency: "EUR" }) },
{ key: "status", header: "Status" },
]}
asOf={endOfDayIn(day, "Europe/London")}
timeZone="Europe/London"
/>
)
}The history functions
The table is built on three plain functions. Use them on the server to answer the same question in an API or a report, so the screen and the export never disagree.
import { compareAt, snapshotAt, stateAt } from "@/lib/as-of"
stateAt(account, "2026-03-02T23:59:59Z") // the record then, or null if it didn't exist
snapshotAt(accounts, asOf) // every record that existed then
compareAt(accounts, asOf) // per record: unchanged, changed (and which fields), added or removedBehaviour
- Inclusive as-of
- A change made exactly at the as-of instant counts. endOfDayIn gives the last millisecond of a day in a time zone, including the days the clocks change.
- No clock
- Left out, “latest” means after every version, not Date.now(). The same props give the same table on the server and in the browser.
- Exact comparison
- Values are compared exactly, so “100” and “100.00” count as a change. Pass equals to compare your own way.
- History in any order
- Versions are applied by time, and ones with the same timestamp in the order given.
- Removed and added rows
- Rows removed since are kept and labelled. Rows added since aren't shown, because they didn't exist yet, and are counted in the summary.
- Compare two past points
- Pass compareTo to mark what changed by another date instead of now.
Accessibility
- Marked in text
- A changed cell shows the current value under the old one, so the change doesn't rely on colour. Screen readers hear “€50,000.00, now €75,000.00”.
- A live summary
- The line above the table says how many values changed and rows were added or removed, and is announced when the date changes.
- Real table markup
- A caption, column headers and the first column as row headers, so each cell is read with its account and column.
- Scrolls on small screens
- The table scrolls sideways in a region named after the caption, which can take keyboard focus.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| records | HistoryRecord[] | — | Each has an id and a history of { at, set } or { at, removed } entries. |
| columns | AsOfColumn[] | — | key, header, and optionally align and format. The first column is the row header. |
| caption | ReactNode | — | The table's name. |
| asOf | Date | string | — | The point in time to show. Left out, the latest values with nothing marked. |
| compareTo | Date | string | latest | What changed values are compared with. |
| equals | (field, a, b) => boolean | Object.is | How two values are compared. |
| locale | string | "en-US" | Locale for dates. |
| timeZone | string | runtime zone | IANA zone for dates. Pass it explicitly when rendering on the server. |
| empty | ReactNode | — | Shown when no row existed at that point. |