@statsig/react-bindings 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/react-bindings",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@statsig/client-core": "3.
|
|
6
|
-
"@statsig/js-client": "3.
|
|
5
|
+
"@statsig/client-core": "3.2.0",
|
|
6
|
+
"@statsig/js-client": "3.2.0"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
9
|
"react": "^16.6.3 || ^17.0.0 || ^18.0.0"
|
|
@@ -6,14 +6,19 @@ const client_core_1 = require("@statsig/client-core");
|
|
|
6
6
|
const js_client_1 = require("@statsig/js-client");
|
|
7
7
|
function useClientAsyncInit(sdkKey, initialUser, statsigOptions = null) {
|
|
8
8
|
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const clientRef = (0, react_1.useRef)(null);
|
|
10
|
+
const client = (0, react_1.useMemo)(() => {
|
|
11
|
+
if (clientRef.current) {
|
|
12
|
+
return clientRef.current;
|
|
13
|
+
}
|
|
14
|
+
const inst = new js_client_1.StatsigClient(sdkKey, initialUser, statsigOptions);
|
|
15
|
+
clientRef.current = inst;
|
|
16
|
+
inst
|
|
12
17
|
.initializeAsync()
|
|
13
18
|
.catch(client_core_1.Log.error)
|
|
14
19
|
.finally(() => setIsLoading(false));
|
|
15
|
-
return
|
|
16
|
-
});
|
|
17
|
-
return { client
|
|
20
|
+
return inst;
|
|
21
|
+
}, []);
|
|
22
|
+
return { client, isLoading };
|
|
18
23
|
}
|
|
19
24
|
exports.useClientAsyncInit = useClientAsyncInit;
|
|
@@ -4,12 +4,16 @@ exports.useClientBootstrapInit = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const js_client_1 = require("@statsig/js-client");
|
|
6
6
|
function useClientBootstrapInit(sdkKey, initialUser, initialValues, statsigOptions = null) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
const clientRef = (0, react_1.useRef)(null);
|
|
8
|
+
return (0, react_1.useMemo)(() => {
|
|
9
|
+
if (clientRef.current) {
|
|
10
|
+
return clientRef.current;
|
|
11
|
+
}
|
|
12
|
+
const inst = new js_client_1.StatsigClient(sdkKey, initialUser, statsigOptions);
|
|
13
|
+
clientRef.current = inst;
|
|
14
|
+
inst.dataAdapter.setData(initialValues);
|
|
15
|
+
inst.initializeSync();
|
|
16
|
+
return inst;
|
|
17
|
+
}, []);
|
|
14
18
|
}
|
|
15
19
|
exports.useClientBootstrapInit = useClientBootstrapInit;
|