@scaleway/use-growthbook 1.0.3 → 1.0.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/CHANGELOG.md +14 -0
- package/dist/AbTestProvider.js +23 -12
- package/dist/index.d.ts +6 -8
- package/dist/index.js +1 -1
- package/dist/useAbTestAttributes.js +9 -7
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @scaleway/use-growthbook
|
|
2
2
|
|
|
3
|
+
## 1.0.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1615](https://github.com/scaleway/scaleway-lib/pull/1615) [`03c4c6b`](https://github.com/scaleway/scaleway-lib/commit/03c4c6be73214dc48096e0c43fcd23a47b0102a4) Thanks [@renovate](https://github.com/apps/renovate)! - Updated dependency `@growthbook/growthbook-react` to `0.20.0`.
|
|
8
|
+
|
|
9
|
+
## 1.0.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1572](https://github.com/scaleway/scaleway-lib/pull/1572) [`57ddd1a`](https://github.com/scaleway/scaleway-lib/commit/57ddd1a39c048675f343c0da8735714f1cb5678a) Thanks [@philibea](https://github.com/philibea)! - when attributes a of provider change there is new instance of growthbook created and can make a desync during render
|
|
14
|
+
|
|
15
|
+
- [#1566](https://github.com/scaleway/scaleway-lib/pull/1566) [`2223dc1`](https://github.com/scaleway/scaleway-lib/commit/2223dc1ec4993b57e4dbeb41f65a8659c63d548c) Thanks [@renovate](https://github.com/apps/renovate)! - Updated dependency `@growthbook/growthbook-react` to `0.19.0`.
|
|
16
|
+
|
|
3
17
|
## 1.0.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/AbTestProvider.js
CHANGED
|
@@ -2,28 +2,31 @@ import { GrowthBookProvider, GrowthBook } from '@growthbook/growthbook-react';
|
|
|
2
2
|
import { useMemo, useCallback, useEffect } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
|
+
const defaultLoadConfig = {
|
|
6
|
+
autoRefresh: false,
|
|
7
|
+
timeout: 500,
|
|
8
|
+
skipCache: false
|
|
9
|
+
};
|
|
5
10
|
const getGrowthBookInstance = _ref => {
|
|
6
11
|
let {
|
|
7
12
|
config: {
|
|
8
13
|
apiHost,
|
|
9
14
|
clientKey,
|
|
10
|
-
enableDevMode
|
|
15
|
+
enableDevMode,
|
|
16
|
+
backgroundSync,
|
|
17
|
+
subscribeToChanges
|
|
11
18
|
},
|
|
12
|
-
attributes,
|
|
13
19
|
trackingCallback
|
|
14
20
|
} = _ref;
|
|
15
21
|
return new GrowthBook({
|
|
16
22
|
apiHost,
|
|
17
23
|
clientKey,
|
|
18
24
|
enableDevMode,
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
trackingCallback,
|
|
26
|
+
backgroundSync,
|
|
27
|
+
subscribeToChanges
|
|
21
28
|
});
|
|
22
29
|
};
|
|
23
|
-
const defaultLoadConfig = {
|
|
24
|
-
autoRefresh: false,
|
|
25
|
-
timeout: 500
|
|
26
|
-
};
|
|
27
30
|
const AbTestProvider = _ref2 => {
|
|
28
31
|
let {
|
|
29
32
|
children,
|
|
@@ -31,21 +34,29 @@ const AbTestProvider = _ref2 => {
|
|
|
31
34
|
trackingCallback,
|
|
32
35
|
errorCallback,
|
|
33
36
|
attributes,
|
|
34
|
-
loadConfig
|
|
37
|
+
loadConfig
|
|
35
38
|
} = _ref2;
|
|
36
39
|
const growthbook = useMemo(() => getGrowthBookInstance({
|
|
37
40
|
config,
|
|
38
|
-
attributes,
|
|
39
41
|
trackingCallback
|
|
40
|
-
}), [trackingCallback, config
|
|
42
|
+
}), [trackingCallback, config]);
|
|
41
43
|
const loadFeature = useCallback(async () => {
|
|
42
44
|
if (config.clientKey) {
|
|
43
|
-
await growthbook.loadFeatures(loadConfig);
|
|
45
|
+
await growthbook.loadFeatures(loadConfig ?? defaultLoadConfig);
|
|
44
46
|
}
|
|
45
47
|
}, [growthbook, config, loadConfig]);
|
|
46
48
|
useEffect(() => {
|
|
47
49
|
loadFeature().catch(errorCallback);
|
|
48
50
|
}, [loadFeature, errorCallback]);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const currentAttributes = growthbook.getAttributes();
|
|
53
|
+
if (currentAttributes !== attributes) {
|
|
54
|
+
growthbook.setAttributes({
|
|
55
|
+
...currentAttributes,
|
|
56
|
+
...attributes
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}, [attributes, growthbook]);
|
|
49
60
|
return jsx(GrowthBookProvider, {
|
|
50
61
|
growthbook: growthbook,
|
|
51
62
|
children: children
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from '@growthbook/growthbook-react';
|
|
2
|
-
export {
|
|
2
|
+
export { FeatureString, FeaturesReady, IfFeatureEnabled, useExperiment, useFeature, useFeatureIsOn, useFeatureValue, useGrowthBook, useGrowthBookSSR, withRunExperiment } from '@growthbook/growthbook-react';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
@@ -7,21 +7,19 @@ type Attributes = Record<string, string | number | undefined>;
|
|
|
7
7
|
/**
|
|
8
8
|
* @param {boolean} [autoRefresh] - false.
|
|
9
9
|
* @param {number} [timeout] - 500.
|
|
10
|
+
* @param {boolean} [skipCache] - false.
|
|
10
11
|
*/
|
|
11
12
|
type LoadConfig = {
|
|
12
13
|
autoRefresh: boolean;
|
|
13
14
|
timeout: number;
|
|
15
|
+
skipCache: boolean;
|
|
14
16
|
};
|
|
17
|
+
type ToolConfig = Pick<Context, 'apiHost' | 'clientKey' | 'enableDevMode' | 'backgroundSync' | 'subscribeToChanges'>;
|
|
18
|
+
type TrackingCallback = NonNullable<Context['trackingCallback']>;
|
|
19
|
+
type ErrorCallback = (error: Error | string) => void | null;
|
|
15
20
|
|
|
16
21
|
declare const useAbTestAttributes: () => [Attributes, (attributes: Attributes) => void];
|
|
17
22
|
|
|
18
|
-
type ToolConfig = {
|
|
19
|
-
apiHost: string;
|
|
20
|
-
clientKey: string;
|
|
21
|
-
enableDevMode: boolean;
|
|
22
|
-
};
|
|
23
|
-
type TrackingCallback = NonNullable<Context['trackingCallback']>;
|
|
24
|
-
type ErrorCallback = (error: Error | string) => void;
|
|
25
23
|
type AbTestProviderProps = {
|
|
26
24
|
children: ReactNode;
|
|
27
25
|
config: ToolConfig;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { useExperiment, useFeature, useFeatureIsOn, useFeatureValue, withRunExperiment } from '@growthbook/growthbook-react';
|
|
1
|
+
export { FeatureString, FeaturesReady, IfFeatureEnabled, useExperiment, useFeature, useFeatureIsOn, useFeatureValue, useGrowthBook, useGrowthBookSSR, withRunExperiment } from '@growthbook/growthbook-react';
|
|
2
2
|
export { useAbTestAttributes } from './useAbTestAttributes.js';
|
|
3
3
|
export { AbTestProvider } from './AbTestProvider.js';
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { useGrowthBook } from '@growthbook/growthbook-react';
|
|
2
|
-
import { useMemo, useCallback } from 'react';
|
|
3
2
|
|
|
4
3
|
const useAbTestAttributes = () => {
|
|
5
4
|
const growthBook = useGrowthBook();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
if (growthBook) {
|
|
6
|
+
const attributes = growthBook.getAttributes();
|
|
7
|
+
const setAttributes = newAttributes => growthBook.setAttributes({
|
|
8
|
+
...attributes,
|
|
9
|
+
...newAttributes
|
|
10
|
+
});
|
|
11
|
+
return [attributes, setAttributes];
|
|
12
|
+
}
|
|
13
|
+
return [{}, () => {}];
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
export { useAbTestAttributes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleway/use-growthbook",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Utility package to expose AB test tool",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"feature flags"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@growthbook/growthbook-react": "0.
|
|
28
|
+
"@growthbook/growthbook-react": "0.20.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"react": "18.2.0"
|