Open History to see the last commit
1import {
2 createCollection,
3 localOnlyCollectionOptions,
4} from "@tanstack/react-db";
5
6export type ApiRequest = {
7 id: string;
8 timestamp: number;
9 method: "GET" | "PATCH" | "POST" | "DELETE";
10 pathname: string;
11 requestBody?: unknown;
12 responseBody?: unknown;
13 search?: string;
14 status: number | "pending";
15 duration: number | null; // null when pending
16};
17
18export const apiRequestsCollection = createCollection(
19 localOnlyCollectionOptions({
20 id: "apiRequests",
21 getKey: (item) => item.id,
22 initialData: [] as ApiRequest[],
23 // onUpdate: async ({ transaction }) => {
24 // // Custom logic before confirming the update
25 // const { original, modified } = transaction.mutations[0];
26 // console.log("Updating from", original, "to", modified);
27 // },
28 }),
29);