24 lines
635 B
TypeScript
24 lines
635 B
TypeScript
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,
|
|
};
|
|
}
|