@statsig/react-bindings 2.0.0 → 2.1.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,15 +1,15 @@
1
1
  {
2
2
  "name": "@statsig/react-bindings",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "dependencies": {
5
- "@statsig/client-core": "2.0.0"
5
+ "@statsig/client-core": "2.1.0"
6
6
  },
7
7
  "peerDependencies": {
8
8
  "react": "^16.6.3 || ^17.0.0 || ^18.0.0"
9
9
  },
10
10
  "optionalDependencies": {
11
- "@statsig/js-client": "2.0.0",
12
- "@statsig/js-on-device-eval-client": "2.0.0"
11
+ "@statsig/js-client": "2.1.0",
12
+ "@statsig/js-on-device-eval-client": "2.1.0"
13
13
  },
14
14
  "type": "commonjs",
15
15
  "main": "./src/index.js",
@@ -1,8 +1,16 @@
1
1
  import { ReactNode } from 'react';
2
- import { StatsigClientInterface } from '@statsig/client-core';
2
+ import { AnyStatsigOptions, StatsigClientInterface, StatsigUser } from '@statsig/client-core';
3
+ type WithClient = {
4
+ client: StatsigClientInterface;
5
+ };
6
+ type WithConfiguration = {
7
+ sdkKey: string;
8
+ user: StatsigUser;
9
+ options?: AnyStatsigOptions;
10
+ };
3
11
  export type StatsigProviderProps = {
4
12
  children: ReactNode | ReactNode[];
5
- client: StatsigClientInterface;
6
13
  loadingComponent?: ReactNode | ReactNode[];
7
- };
8
- export declare function StatsigProvider({ client, children, loadingComponent, }: StatsigProviderProps): JSX.Element;
14
+ } & (WithClient | WithConfiguration);
15
+ export declare function StatsigProvider(props: StatsigProviderProps): JSX.Element;
16
+ export {};
@@ -5,8 +5,12 @@ 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, loadingComponent, }) {
8
+ const useClientAsyncInit_1 = require("./useClientAsyncInit");
9
+ function StatsigProvider(props) {
9
10
  const [renderVersion, setRenderVersion] = (0, react_1.useState)(0);
11
+ const client = 'client' in props
12
+ ? props.client
13
+ : (0, useClientAsyncInit_1.useClientAsyncInit)(props.sdkKey, props.user).client;
10
14
  (0, react_1.useEffect)(() => {
11
15
  const onValuesUpdated = () => {
12
16
  setRenderVersion((v) => v + 1);
@@ -21,9 +25,9 @@ function StatsigProvider({ client, children, loadingComponent, }) {
21
25
  };
22
26
  }, [client]);
23
27
  const contextValue = (0, react_1.useMemo)(() => ({ renderVersion, client }), [renderVersion, client]);
24
- return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: loadingComponent == null || _isReady(client)
25
- ? children
26
- : loadingComponent }));
28
+ return ((0, jsx_runtime_1.jsx)(StatsigContext_1.default.Provider, { value: contextValue, children: props.loadingComponent == null || _isReady(client)
29
+ ? props.children
30
+ : props.loadingComponent }));
27
31
  }
28
32
  exports.StatsigProvider = StatsigProvider;
29
33
  function _isReady(client) {