-
Notifications
You must be signed in to change notification settings - Fork 21
/
App.js
65 lines (53 loc) · 1.51 KB
/
App.js
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
65
/**
* LaunchDarkly Hello React Native App
*
* @format
* @flow strict-local
*/
import React, { useState, useEffect } from 'react';
import type { Node } from 'react';
import { SafeAreaView, StatusBar, Text } from 'react-native';
import LDClient from 'launchdarkly-react-native-client-sdk';
const App: () => Node = () => {
const mobileKey = 'MOBILE_KEY';
const flagKey = 'dev-test-flag';
const [client, setClient] = useState(null);
const [flagValue, setFlagValue] = useState(null);
async function evalFlag() {
let res = await client.boolVariationDetail(flagKey, false);
console.log('This is the reason from the SDK: ' + JSON.stringify(res));
if (res != flagValue) {
setFlagValue(JSON.stringify(res));
}
}
useEffect(() => {
async function initializeClient() {
let ldClient = new LDClient();
let config = { mobileKey, debugMode: true, evaluationReasons: true };
let user = { kind: 'user', key: 'test-key' };
try {
await ldClient.configure(config, user);
} catch (err) {
console.log(err);
}
setClient(ldClient);
}
if (mobileKey === '') {
console.log('Please edit App.js to set mobileKey to your LaunchDarkly mobile key first');
return;
}
if (client == null) {
initializeClient();
} else {
evalFlag();
}
});
return (
<SafeAreaView>
<Text>
Feature flag '{flagKey}' is {JSON.stringify(flagValue)} for this user
</Text>
</SafeAreaView>
);
};
export default App;