blob: b91399e0914adb366c504cca854f519b5acde612 (
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
|
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);
}
|