-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathApp.tsx
64 lines (55 loc) · 2.1 KB
/
App.tsx
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import "./App.css";
import {OpenFeature, OpenFeatureProvider, useFlag} from "@openfeature/react-sdk";
import {GoFeatureFlagWebProvider} from "@openfeature/go-feature-flag-web-provider";
import {AccountSelector} from "./components/account-selector.tsx";
import {login} from "./service/login.tsx";
import {Badges} from "./components/badges.tsx";
const goFeatureFlagWebProvider = new GoFeatureFlagWebProvider({
endpoint: "http://localhost:1031"
});
OpenFeature.setContext({
targetingKey: "user-1",
admin: false
});
OpenFeature.setProvider(goFeatureFlagWebProvider);
function App() {
return (
<OpenFeatureProvider>
<Page/>
</OpenFeatureProvider>
);
}
function Page() {
const {value: hideLogo} = useFlag("hide-logo", false);
const {value: titleFlag} = useFlag("title-flag", "GO Feature Flag");
const onLoginChange = (name: string) => {
const ctx = login(name);
OpenFeature.setContext(ctx);
}
return (
<>
<div className="flex justify-center items-center pt-10">
<a href="https://gofeatureflag.org" target="_blank">
{!hideLogo && <img src="/public/logo.png" className="max-w-72" alt="GO Feature Flag logo"/>}
</a>
</div>
<div className="flex justify-center items-center">
<h2 className={"text-xl text-gray-200 pb-5"}>Openfeature React example app</h2>
</div>
<AccountSelector onChange={onLoginChange}/>
<div className="flex justify-center items-center mt-12 gap-4">
<span className={"text-sm text-gray-200"}>Title comming from the feature flag:</span>
<h1 className={"text-2xl text-gray-200"}>{titleFlag}</h1>
</div>
<Badges/>
<h1 className={"flex text-md justify-center items-center place-items-center mt-28 text-gray-200"}>
Evaluation context used:</h1>
<div className={"flex justify-center items-center place-items-center "}>
<pre className={"text-gray-50 bg-zinc-700 py-3 px-10 rounded min-w-xl max-w-2xl"}>
<code className="language-json">{JSON.stringify(OpenFeature.getContext(), null, 2)}</code>
</pre>
</div>
</>
);
}
export default App;