a tool for shared writing and social publishing
1"use client";
2import { createContext, useContext } from "react";
3import type { PubLeafletContent } from "lexicons/api";
4
5export type Page = PubLeafletContent.Main["pages"][number];
6
7export type LeafletContentContextValue = {
8 pages: Page[];
9};
10
11const LeafletContentContext = createContext<LeafletContentContextValue | null>(null);
12
13export function useLeafletContent() {
14 const ctx = useContext(LeafletContentContext);
15 if (!ctx) throw new Error("useLeafletContent must be used within LeafletContentProvider");
16 return ctx;
17}
18
19export function useLeafletContentOptional() {
20 return useContext(LeafletContentContext);
21}
22
23export function LeafletContentProvider({
24 children,
25 value,
26}: {
27 children: React.ReactNode;
28 value: LeafletContentContextValue;
29}) {
30 return (
31 <LeafletContentContext.Provider value={value}>
32 {children}
33 </LeafletContentContext.Provider>
34 );
35}