-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdynamicMdContext.tsx
More file actions
40 lines (33 loc) · 1.01 KB
/
dynamicMdContext.tsx
File metadata and controls
40 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use client";
import { createContext, ReactNode, useContext, useState } from "react";
import { DynamicMarkdownSection } from "./pageContent";
export interface IDynamicMdContext {
dynamicMdContent: DynamicMarkdownSection[];
setDynamicMdContent: React.Dispatch<React.SetStateAction<DynamicMarkdownSection[]>>;
}
const DynamicMdContext = createContext<IDynamicMdContext | null>(null);
export function useDynamicMdContext() {
const context = useContext(DynamicMdContext);
if (!context) {
throw new Error(
"useDynamicMdContext must be used within a DynamicMdProvider"
);
}
return context;
}
export function useDynamicMdContextOptional() {
return useContext(DynamicMdContext);
}
export function DynamicMdProvider({
children,
}: {
children: ReactNode;
}) {
const [dynamicMdContent, setDynamicMdContent] =
useState<DynamicMarkdownSection[]>([]);
return (
<DynamicMdContext.Provider value={{ dynamicMdContent, setDynamicMdContent }}>
{children}
</DynamicMdContext.Provider>
);
}