I think I have a working document cache solution that's actually pretty good.

This commit is contained in:
2025-07-03 16:24:58 -07:00
parent db4ce36c27
commit 503c98c895
26 changed files with 317 additions and 212 deletions

View File

@@ -0,0 +1,23 @@
import type { DocumentId } from "@/lib/types";
import { useContext } from "react";
import { DocumentContext } from "./DocumentContext";
export function useDocument(id: DocumentId) {
const ctx = useContext(DocumentContext);
if (!ctx)
throw new Error("useDocument must be used within a DocumentProvider");
return {
docResult: ctx.cache.documents[id],
dispatch: ctx.dispatch,
};
}
export function useDocumentCache() {
const ctx = useContext(DocumentContext);
if (!ctx)
throw new Error("useDocument must be used within a DocumentProvider");
return {
cache: ctx.cache,
dispatch: ctx.dispatch,
};
}