Skip to content

Commit 21e5672

Browse files
authored
feat: [FFM-6864]: Log when required props are missing (#6)
1 parent 5156edd commit 21e5672

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

examples/get-started/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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": "1.2.0",
3+
"version": "1.3.0",
44
"author": "Harness",
55
"license": "Apache-2.0",
66
"module": "dist/esm/index.js",

src/context/FFContext.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface FFContextProviderProps extends PropsWithChildren {
3636
fallback?: ReactNode
3737
async?: boolean
3838
initialEvaluations?: Evaluation[]
39-
onError?: (event: NetworkError, error?: unknown) => void
39+
onError?: (event: NetworkError | 'PropsError', error?: unknown) => void
4040
}
4141

4242
export const FFContextProvider: FC<FFContextProviderProps> = ({
@@ -53,7 +53,21 @@ export const FFContextProvider: FC<FFContextProviderProps> = ({
5353
const [flags, setFlags] = useState<FFContextValue['flags']>({})
5454

5555
useEffect(() => {
56-
if (apiKey && target) {
56+
if (!apiKey) {
57+
console.error('[FF-SDK] apiKey prop is required')
58+
onError('PropsError', { message: 'apiKey prop is required' })
59+
}
60+
}, [apiKey])
61+
62+
useEffect(() => {
63+
if (!target?.identifier) {
64+
console.error('[FF-SDK] target prop is required')
65+
onError('PropsError', { message: 'target prop is required' })
66+
}
67+
}, [target?.identifier])
68+
69+
useEffect(() => {
70+
if (apiKey && target?.identifier) {
5771
const client = initialize(apiKey, target, options)
5872

5973
setLoading(true)

0 commit comments

Comments
 (0)