blob: dad725d9b6c7f6096a2618b7990ab994cf5e494d (
plain) (
blame)
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
|
import React from "react";
import { useEffect } from "react";
const FeaturesContext = React.createContext();
export function FeaturesProvider({ children }) {
const [features, setFeatures] = React.useState([]);
useEffect(() => {
fetch("/api/v1/features")
.then((response) => response.json())
.then((data) => {
console.debug("features:", data);
setFeatures(data);
})
.catch((error) => {
console.error(error);
});
}, []);
return (
<FeaturesContext.Provider value={features}>
{children}
</FeaturesContext.Provider>
);
}
export function useFeatures() {
return React.useContext(FeaturesContext);
}
|