@statsig/react-bindings-on-device-eval 3.1.0 → 3.2.0-beta.1

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-on-device-eval",
3
- "version": "3.1.0",
3
+ "version": "3.2.0-beta.1",
4
4
  "dependencies": {
5
- "@statsig/client-core": "3.1.0",
6
- "@statsig/js-on-device-eval-client": "3.1.0"
5
+ "@statsig/client-core": "3.2.0-beta.1",
6
+ "@statsig/js-on-device-eval-client": "3.2.0-beta.1"
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_on_device_eval_client_1 = require("@statsig/js-on-device-eval-client");
7
7
  function useOnDeviceClientAsyncInit(sdkKey, statsigOptions = null) {
8
8
  const [isLoading, setIsLoading] = (0, react_1.useState)(true);
9
- const [args] = (0, react_1.useState)(() => {
10
- const client = new js_on_device_eval_client_1.StatsigOnDeviceEvalClient(sdkKey, statsigOptions);
11
- client
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_on_device_eval_client_1.StatsigOnDeviceEvalClient(sdkKey, 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 { client, sdkKey };
16
- });
17
- return { client: args.client, isLoading };
20
+ return inst;
21
+ }, []);
22
+ return { client, isLoading };
18
23
  }
19
24
  exports.useOnDeviceClientAsyncInit = useOnDeviceClientAsyncInit;
@@ -4,12 +4,16 @@ exports.useOnDeviceClientBootstrapInit = void 0;
4
4
  const react_1 = require("react");
5
5
  const js_on_device_eval_client_1 = require("@statsig/js-on-device-eval-client");
6
6
  function useOnDeviceClientBootstrapInit(sdkKey, initialValues, statsigOptions = null) {
7
- const [args] = (0, react_1.useState)(() => {
8
- const client = new js_on_device_eval_client_1.StatsigOnDeviceEvalClient(sdkKey, statsigOptions);
9
- client.dataAdapter.setData(initialValues);
10
- client.initializeSync();
11
- return { client, initialValues, sdkKey };
12
- });
13
- return args.client;
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_on_device_eval_client_1.StatsigOnDeviceEvalClient(sdkKey, statsigOptions);
13
+ clientRef.current = inst;
14
+ inst.dataAdapter.setData(initialValues);
15
+ inst.initializeSync();
16
+ return inst;
17
+ }, []);
14
18
  }
15
19
  exports.useOnDeviceClientBootstrapInit = useOnDeviceClientBootstrapInit;