@statsig/react-bindings 3.15.3 → 3.15.5
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statsig/react-bindings",
|
|
3
|
-
"version": "3.15.
|
|
3
|
+
"version": "3.15.5",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"homepage": "https://github.com/statsig-io/js-client-monorepo",
|
|
6
6
|
"repository": {
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"directory": "packages/react-bindings"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@statsig/client-core": "3.15.
|
|
13
|
-
"@statsig/js-client": "3.15.
|
|
12
|
+
"@statsig/client-core": "3.15.5",
|
|
13
|
+
"@statsig/js-client": "3.15.5"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"react": "^16.6.3 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
package/src/StatsigContext.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
|
2
2
|
export interface StatsigContext {
|
|
3
3
|
readonly renderVersion: number;
|
|
4
4
|
readonly client: PrecomputedEvaluationsInterface;
|
|
5
|
+
readonly isLoading: boolean;
|
|
5
6
|
}
|
|
6
7
|
declare const _default: import("react").Context<StatsigContext>;
|
|
7
8
|
export default _default;
|
package/src/StatsigContext.js
CHANGED
package/src/StatsigProvider.js
CHANGED
|
@@ -19,25 +19,36 @@ exports.StatsigProvider = StatsigProvider;
|
|
|
19
19
|
function ConfigBasedStatsigProvider(props) {
|
|
20
20
|
const [renderVersion, setRenderVersion] = (0, react_1.useState)(0);
|
|
21
21
|
const client = (0, useClientAsyncInit_1.useClientAsyncInit)(props.sdkKey, props.user, props.options).client;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(!_isReady(client));
|
|
23
|
+
useStatsigClientSetup(client, setRenderVersion, setIsLoading);
|
|
24
|
+
const contextValue = (0, react_1.useMemo)(() => ({
|
|
25
|
+
renderVersion,
|
|
26
|
+
client,
|
|
27
|
+
isLoading,
|
|
28
|
+
}), [renderVersion, client, isLoading]);
|
|
29
|
+
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: props.loadingComponent == null || !contextValue.isLoading
|
|
25
30
|
? props.children
|
|
26
31
|
: props.loadingComponent }));
|
|
27
32
|
}
|
|
28
33
|
function ClientBasedStatsigProvider(props) {
|
|
29
34
|
const [renderVersion, setRenderVersion] = (0, react_1.useState)(0);
|
|
30
35
|
const client = props.client;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(!_isReady(client));
|
|
37
|
+
useStatsigClientSetup(client, setRenderVersion, setIsLoading);
|
|
38
|
+
const contextValue = (0, react_1.useMemo)(() => ({
|
|
39
|
+
renderVersion,
|
|
40
|
+
client,
|
|
41
|
+
isLoading,
|
|
42
|
+
}), [renderVersion, client, isLoading]);
|
|
43
|
+
return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: props.loadingComponent == null || !contextValue.isLoading
|
|
34
44
|
? props.children
|
|
35
45
|
: props.loadingComponent }));
|
|
36
46
|
}
|
|
37
|
-
function useStatsigClientSetup(client, setRenderVersion) {
|
|
47
|
+
function useStatsigClientSetup(client, setRenderVersion, setIsLoading) {
|
|
38
48
|
(0, react_1.useEffect)(() => {
|
|
39
49
|
const onValuesUpdated = () => {
|
|
40
50
|
setRenderVersion((v) => v + 1);
|
|
51
|
+
setIsLoading(!_isReady(client));
|
|
41
52
|
};
|
|
42
53
|
client_core_1.SDKType._setBindingType('react');
|
|
43
54
|
client.$on('values_updated', onValuesUpdated);
|
|
@@ -2,6 +2,7 @@ import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
|
|
|
2
2
|
type HositedFuncs = Pick<PrecomputedEvaluationsInterface, 'checkGate' | 'getFeatureGate' | 'getDynamicConfig' | 'getExperiment' | 'getLayer' | 'getParameterStore' | 'logEvent'>;
|
|
3
3
|
type Output = HositedFuncs & {
|
|
4
4
|
client: PrecomputedEvaluationsInterface;
|
|
5
|
+
isLoading: boolean;
|
|
5
6
|
};
|
|
6
7
|
export declare function useStatsigClient(): Output;
|
|
7
8
|
export {};
|
package/src/useStatsigClient.js
CHANGED
|
@@ -6,7 +6,7 @@ const client_core_1 = require("@statsig/client-core");
|
|
|
6
6
|
const NoopEvaluationsClient_1 = require("./NoopEvaluationsClient");
|
|
7
7
|
const StatsigContext_1 = require("./StatsigContext");
|
|
8
8
|
function useStatsigClient() {
|
|
9
|
-
const { client: anyClient, renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
9
|
+
const { client: anyClient, renderVersion, isLoading, } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
10
|
const client = (0, react_1.useMemo)(() => {
|
|
11
11
|
if ((0, NoopEvaluationsClient_1.isNoopClient)(anyClient)) {
|
|
12
12
|
client_core_1.Log.warn('Attempting to retrieve a StatsigClient but none was set.');
|
|
@@ -49,6 +49,7 @@ function useStatsigClient() {
|
|
|
49
49
|
getLayer,
|
|
50
50
|
getParameterStore,
|
|
51
51
|
logEvent,
|
|
52
|
+
isLoading,
|
|
52
53
|
};
|
|
53
54
|
}, [
|
|
54
55
|
client,
|
|
@@ -59,6 +60,7 @@ function useStatsigClient() {
|
|
|
59
60
|
getLayer,
|
|
60
61
|
getParameterStore,
|
|
61
62
|
logEvent,
|
|
63
|
+
isLoading,
|
|
62
64
|
]);
|
|
63
65
|
}
|
|
64
66
|
exports.useStatsigClient = useStatsigClient;
|
package/src/useStatsigUser.js
CHANGED
|
@@ -4,28 +4,30 @@ exports.useStatsigUser = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const StatsigContext_1 = require("./StatsigContext");
|
|
6
6
|
const useStatsigClient_1 = require("./useStatsigClient");
|
|
7
|
+
function getClientUser(client) {
|
|
8
|
+
const context = client.getContext();
|
|
9
|
+
return context.user;
|
|
10
|
+
}
|
|
7
11
|
function useStatsigUser() {
|
|
8
12
|
const { client } = (0, useStatsigClient_1.useStatsigClient)();
|
|
9
13
|
const { renderVersion } = (0, react_1.useContext)(StatsigContext_1.default);
|
|
10
|
-
const deps = [client, renderVersion];
|
|
11
14
|
const memoUser = (0, react_1.useMemo)(() => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}, deps);
|
|
15
|
+
return getClientUser(client);
|
|
16
|
+
}, [client, renderVersion]);
|
|
15
17
|
return {
|
|
16
18
|
user: memoUser,
|
|
17
19
|
updateUserSync: (0, react_1.useCallback)((arg) => {
|
|
18
20
|
if (typeof arg === 'function') {
|
|
19
|
-
arg = arg(
|
|
21
|
+
arg = arg(getClientUser(client));
|
|
20
22
|
}
|
|
21
23
|
return client.updateUserSync(arg);
|
|
22
|
-
},
|
|
24
|
+
}, [client]),
|
|
23
25
|
updateUserAsync: (0, react_1.useCallback)((arg) => {
|
|
24
26
|
if (typeof arg === 'function') {
|
|
25
|
-
arg = arg(
|
|
27
|
+
arg = arg(getClientUser(client));
|
|
26
28
|
}
|
|
27
29
|
return client.updateUserAsync(arg);
|
|
28
|
-
},
|
|
30
|
+
}, [client]),
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
33
|
exports.useStatsigUser = useStatsigUser;
|