-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSiteConfigContext.jsx
More file actions
36 lines (30 loc) · 963 Bytes
/
SiteConfigContext.jsx
File metadata and controls
36 lines (30 loc) · 963 Bytes
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
import React, { createContext, useContext, useState, useEffect } from 'react';
import piml from 'piml';
const SiteConfigContext = createContext();
export const useSiteConfig = () => useContext(SiteConfigContext);
export const SiteConfigProvider = ({ children }) => {
const [config, setConfig] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchConfig = async () => {
try {
const response = await fetch('/site-config.piml');
if (response.ok) {
const text = await response.text();
const parsed = piml.parse(text);
setConfig(parsed.config);
}
} catch (error) {
console.error('Failed to load site config:', error);
} finally {
setLoading(false);
}
};
fetchConfig();
}, []);
return (
<SiteConfigContext.Provider value={{ config, loading }}>
{children}
</SiteConfigContext.Provider>
);
};