Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/renovate-446b7ad.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@scaleway/use-growthbook': patch
---

Updated dependency `@growthbook/growthbook-react` to `0.24.0`.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"type": "module",
"packageManager": "pnpm@8.15.4",
"engines": {
"node": ">=18.x",
"pnpm": ">=7.x"
"node": ">=20.x",
"pnpm": ">=8.x"
},
"devDependencies": {
"@babel/core": "7.24.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/use-growthbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"feature flags"
],
"dependencies": {
"@growthbook/growthbook-react": "0.21.0"
"@growthbook/growthbook-react": "0.24.0"
},
"devDependencies": {
"react": "18.2.0"
Expand Down
12 changes: 7 additions & 5 deletions packages/use-growthbook/src/AbTestProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ export const AbTestProvider = ({
useEffect(() => {
const currentAttributes = growthbook.getAttributes()
if (currentAttributes !== attributes) {
growthbook.setAttributes({
...currentAttributes,
...attributes,
})
growthbook
.setAttributes({
...currentAttributes,
...attributes,
})
.catch(errorCallback)
}
}, [attributes, growthbook])
}, [attributes, growthbook, errorCallback])

return (
<GrowthBookProvider growthbook={growthbook}>{children}</GrowthBookProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { GrowthBook as GBType } from '@growthbook/growthbook-react'
import { jest } from '@jest/globals'
import type { ReactNode } from 'react'

const GrowthBook = jest.fn(() => ({
loadFeatures: jest.fn(),
getAttributes: jest.fn(),
setAttributes: jest.fn(),
loadFeatures: jest.fn<GBType['loadFeatures']>(),
getAttributes: jest.fn<GBType['getAttributes']>(),
setAttributes: jest.fn<GBType['setAttributes']>(() => Promise.resolve()),
}))
const GrowthBookProvider = ({ children }: { children: ReactNode }) => children

Expand Down
5 changes: 2 additions & 3 deletions packages/use-growthbook/src/__tests__/AbTestProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ type TrackingCallback = ComponentProps<
type ErrorCallback = ComponentProps<typeof AbTestProvider>['errorCallback']

describe('AbTestProvider', () => {
let trackingCallback: TrackingCallback
let errorCallback: ErrorCallback
const trackingCallback = jest.fn<TrackingCallback>()
const errorCallback: ErrorCallback = () => null

beforeEach(() => {
trackingCallback = jest.fn()
jest.clearAllMocks()
})
it('should init GrowthBook once', () => {
Expand Down
9 changes: 4 additions & 5 deletions packages/use-growthbook/src/__tests__/useAbTestAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ jest.mock('@growthbook/growthbook-react')

describe('useAbTestAttributes', () => {
let getAttributes: () => Attributes
let setAttributes: (attributes: Attributes) => null | undefined
let setAttributes: (attributes: Attributes) => Promise<void>

beforeEach(() => {
getAttributes = jest
.fn()
.mockReturnValue({ foo: 'bar' }) as () => Attributes
setAttributes = jest.fn() as (attributes: Attributes) => null | undefined
getAttributes = jest.fn<() => Attributes>().mockReturnValue({ foo: 'bar' })
setAttributes = jest.fn(() => Promise.resolve())

jest.spyOn(growthbook, 'useGrowthBook').mockReturnValue({
getAttributes,
setAttributes,
Expand Down
8 changes: 2 additions & 6 deletions packages/use-growthbook/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Context } from '@growthbook/growthbook-react'
import type { Context, GrowthBook } from '@growthbook/growthbook-react'

export type Attributes = Record<string, string | number | undefined>

Expand All @@ -7,11 +7,7 @@ export type Attributes = Record<string, string | number | undefined>
* @param {number} [timeout] - 500.
* @param {boolean} [skipCache] - false.
*/
export type LoadConfig = {
autoRefresh: boolean
timeout: number
skipCache: boolean
}
export type LoadConfig = NonNullable<Parameters<GrowthBook['loadFeatures']>[0]>

export type ToolConfig = Pick<
Context,
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.