25 lines
765 B
TypeScript
25 lines
765 B
TypeScript
import { createContext, useContext, type ReactNode } from "react";
|
|
|
|
import type { ContentStore } from "@/lib/content-types";
|
|
|
|
const ContentContext = createContext<ContentStore | null>(null);
|
|
|
|
/** เนื้อหาที่แก้ได้ (โรงหนัง/คำศัพท์/footer) จาก loader ของ root */
|
|
export function ContentProvider({
|
|
content,
|
|
children,
|
|
}: {
|
|
content: ContentStore;
|
|
children: ReactNode;
|
|
}) {
|
|
return (
|
|
<ContentContext.Provider value={content}>{children}</ContentContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useContent(): ContentStore {
|
|
const value = useContext(ContentContext);
|
|
if (!value) throw new Error("useContent ต้องถูกใช้ภายใน <ContentProvider>");
|
|
return value;
|
|
}
|