1import { useState, useEffect } from "react";
3export const useMarkdownContent = (path: string) => {
4 const [content, setContent] = useState<string>("");
5 const [error, setError] = useState<string | null>(null);
7 useEffect(() => {
8 const fetchContent = async () => {
9 try {
10 const response = await fetch(path);
11 if (!response.ok) {
12 throw new Error(
13 `Failed to load markdown content: ${response.statusText}`,
14 );
15 }
16 const text = await response.text();
17 setContent(text);
18 } catch (err) {
19 setError(
20 err instanceof Error
21 ? err.message
22 : "Failed to load markdown content",
23 );
24 }
25 };
27 fetchContent();
28 }, [path]);
30 return { content, error };
31};