@statsig/react-bindings 1.5.0 → 1.7.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,8 +1,8 @@
1
1
  {
2
2
  "name": "@statsig/react-bindings",
3
- "version": "1.5.0",
3
+ "version": "1.7.0",
4
4
  "dependencies": {
5
- "@statsig/client-core": "1.5.0"
5
+ "@statsig/client-core": "1.7.0"
6
6
  },
7
7
  "peerDependencies": {
8
8
  "react": "^16.6.3 || ^17.0.0 || ^18.0.0"
@@ -15,7 +15,7 @@ const _noop = () => {
15
15
  // noop
16
16
  };
17
17
  const _noopAsync = () => Promise.resolve();
18
- const NOOP_DETAILS = { reason: 'Error' };
18
+ const NOOP_DETAILS = { reason: 'Error:NoClient' };
19
19
  const _defaultEvaluation = (type) => {
20
20
  return (...args) => {
21
21
  const name = typeof args[0] === 'string' ? args[0] : args[1];
@@ -3,5 +3,6 @@ import { StatsigClientInterface } from '@statsig/client-core';
3
3
  export type StatsigProviderProps = {
4
4
  children: ReactNode | ReactNode[];
5
5
  client: StatsigClientInterface;
6
+ loadingComponent?: ReactNode | ReactNode[];
6
7
  };
7
- export declare function StatsigProvider({ client, children, }: StatsigProviderProps): JSX.Element;
8
+ export declare function StatsigProvider({ client, children, loadingComponent, }: StatsigProviderProps): JSX.Element;
@@ -5,7 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const react_1 = require("react");
6
6
  const client_core_1 = require("@statsig/client-core");
7
7
  const StatsigContext_1 = require("./StatsigContext");
8
- function StatsigProvider({ client, children, }) {
8
+ function StatsigProvider({ client, children, loadingComponent, }) {
9
9
  const [renderVersion, setRenderVersion] = (0, react_1.useState)(0);
10
10
  (0, react_1.useEffect)(() => {
11
11
  const onValuesUpdated = () => {
@@ -14,17 +14,19 @@ function StatsigProvider({ client, children, }) {
14
14
  client_core_1.SDKType._setBindingType('react');
15
15
  client.$on('values_updated', onValuesUpdated);
16
16
  return () => {
17
- client.shutdown().catch((error) => {
18
- client_core_1.Log.error('An error occured during shutdown', error);
19
- });
17
+ client
18
+ .flush()
19
+ .catch((err) => client_core_1.Log.error('An error occured during flush', err));
20
20
  client.off('values_updated', onValuesUpdated);
21
21
  };
22
22
  }, [client]);
23
23
  const contextValue = (0, react_1.useMemo)(() => ({ renderVersion, client }), [renderVersion, client]);
24
- return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: _shouldRender(client) ? children : null }));
24
+ return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: loadingComponent == null || _isReady(client)
25
+ ? children
26
+ : loadingComponent }));
25
27
  }
26
28
  exports.StatsigProvider = StatsigProvider;
27
- function _shouldRender(client) {
29
+ function _isReady(client) {
28
30
  if ('isNoop' in client) {
29
31
  return true;
30
32
  }
@@ -1,6 +1,7 @@
1
1
  import { PrecomputedEvaluationsInterface } from '@statsig/client-core';
2
2
  type HositedFuncs = Pick<PrecomputedEvaluationsInterface, 'checkGate' | 'getFeatureGate' | 'getDynamicConfig' | 'getExperiment' | 'getLayer' | 'logEvent'>;
3
- export declare function useStatsigClient(): HositedFuncs & {
3
+ type Output = HositedFuncs & {
4
4
  client: PrecomputedEvaluationsInterface;
5
5
  };
6
+ export declare function useStatsigClient(): Output;
6
7
  export {};
@@ -16,29 +16,45 @@ function useStatsigClient() {
16
16
  return NoopEvaluationsClient_1.NoopEvaluationsClient;
17
17
  }, [anyClient, renderVersion]);
18
18
  const deps = [client, renderVersion];
19
- return {
19
+ const checkGate = (0, react_1.useCallback)((name, options) => {
20
+ return client.checkGate(name, options);
21
+ }, deps);
22
+ const getFeatureGate = (0, react_1.useCallback)((name, options) => {
23
+ return client.getFeatureGate(name, options);
24
+ }, deps);
25
+ const getDynamicConfig = (0, react_1.useCallback)((name, options) => {
26
+ return client.getDynamicConfig(name, options);
27
+ }, deps);
28
+ const getExperiment = (0, react_1.useCallback)((name, options) => {
29
+ return client.getExperiment(name, options);
30
+ }, deps);
31
+ const getLayer = (0, react_1.useCallback)((name, options) => {
32
+ return client.getLayer(name, options);
33
+ }, deps);
34
+ const logEvent = (0, react_1.useCallback)((eventName, value, metadata) => {
35
+ if (typeof eventName === 'string') {
36
+ return client.logEvent(eventName, value, metadata);
37
+ }
38
+ return client.logEvent(eventName);
39
+ }, deps);
40
+ return (0, react_1.useMemo)(() => {
41
+ return {
42
+ client,
43
+ checkGate,
44
+ getFeatureGate,
45
+ getDynamicConfig,
46
+ getExperiment,
47
+ getLayer,
48
+ logEvent,
49
+ };
50
+ }, [
20
51
  client,
21
- checkGate: (0, react_1.useCallback)((name, options) => {
22
- return client.checkGate(name, options);
23
- }, deps),
24
- getFeatureGate: (0, react_1.useCallback)((name, options) => {
25
- return client.getFeatureGate(name, options);
26
- }, deps),
27
- getDynamicConfig: (0, react_1.useCallback)((name, options) => {
28
- return client.getDynamicConfig(name, options);
29
- }, deps),
30
- getExperiment: (0, react_1.useCallback)((name, options) => {
31
- return client.getExperiment(name, options);
32
- }, deps),
33
- getLayer: (0, react_1.useCallback)((name, options) => {
34
- return client.getLayer(name, options);
35
- }, deps),
36
- logEvent: (0, react_1.useCallback)((eventName, value, metadata) => {
37
- if (typeof eventName === 'string') {
38
- return client.logEvent(eventName, value, metadata);
39
- }
40
- return client.logEvent(eventName);
41
- }, deps),
42
- };
52
+ checkGate,
53
+ getFeatureGate,
54
+ getDynamicConfig,
55
+ getExperiment,
56
+ getLayer,
57
+ logEvent,
58
+ ]);
43
59
  }
44
60
  exports.useStatsigClient = useStatsigClient;