Skip to content

Commit 87898bd

Browse files
authored
feat: [FFM-12320]: Reinit on options change (#25)
1 parent d9611e4 commit 87898bd

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@harnessio/ff-react-client-sdk",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"author": "Harness",
55
"license": "Apache-2.0",
66
"module": "dist/esm/index.js",

src/context/FFContext.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ import {
44
PropsWithChildren,
55
ReactNode,
66
useEffect,
7+
useMemo,
78
useRef,
89
useState
910
} from 'react'
1011
import {
12+
DefaultVariationEventPayload,
1113
Evaluation,
1214
Event as FFEvent,
1315
initialize,
1416
Options,
1517
Result as InitializeResult,
16-
Target,
17-
DefaultVariationEventPayload
18+
Target
1819
} from '@harnessio/ff-javascript-client-sdk'
1920
import omit from 'lodash.omit'
2021

22+
export { Event } from '@harnessio/ff-javascript-client-sdk'
23+
2124
export interface FFContextValue {
2225
loading: boolean
2326
flags: Record<string, any>
@@ -33,7 +36,7 @@ export type NetworkError =
3336
| FFEvent.ERROR_FETCH_FLAGS
3437
| FFEvent.ERROR_METRICS
3538

36-
export interface FFContextProviderProps extends PropsWithChildren {
39+
export interface FFContextProviderProps extends PropsWithChildren<unknown> {
3740
apiKey: string
3841
target: Target
3942
options?: Options
@@ -157,11 +160,26 @@ export const FFContextProvider: FC<FFContextProviderProps> = ({
157160
client.close()
158161
}
159162
}
160-
}, [apiKey, JSON.stringify(target), initialEvaluations])
163+
}, [
164+
apiKey,
165+
JSON.stringify(target),
166+
initialEvaluations,
167+
options?.baseUrl,
168+
options?.eventUrl,
169+
options?.streamEnabled,
170+
options?.pollingEnabled
171+
])
172+
173+
const value = useMemo(
174+
() => ({ loading, flags, client: clientInstance }),
175+
[loading, flags, clientInstance]
176+
)
161177

162178
return (
163-
<FFContext.Provider value={{ loading, flags, client: clientInstance }}>
179+
<FFContext.Provider value={value}>
164180
{!asyncMode && loading ? fallback : children}
165181
</FFContext.Provider>
166182
)
167183
}
184+
185+
FFContextProvider.displayName = 'FFContextProvider'

0 commit comments

Comments
 (0)