@harnessio/ff-react-client-sdk
Advanced tools
Comparing version 1.7.0 to 1.8.0
import { ComponentType } from 'react'; | ||
import { FFContextValue } from '../context/FFContext'; | ||
export declare function withFeatureFlags<C>(WrappedComponent: ComponentType<C & FFContextValue>): (props: C) => JSX.Element; | ||
export declare function withFeatureFlags<C>(WrappedComponent: ComponentType<C & { | ||
flags: FFContextValue['flags']; | ||
loading: FFContextValue['loading']; | ||
}>): (props: C) => JSX.Element; |
import { ComponentType } from 'react'; | ||
import { FFContextValue } from '../context/FFContext'; | ||
export declare function withFeatureFlags<C>(WrappedComponent: ComponentType<C & FFContextValue>): (props: C) => JSX.Element; | ||
export declare function withFeatureFlags<C>(WrappedComponent: ComponentType<C & { | ||
flags: FFContextValue['flags']; | ||
loading: FFContextValue['loading']; | ||
}>): (props: C) => JSX.Element; |
{ | ||
"name": "@harnessio/ff-react-client-sdk", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"author": "Harness", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -258,3 +258,3 @@ # React.js Client SDK For Harness Feature Flags | ||
The `useFeatureFlagsLoading` hook returns a boolean value indicating whether or not the SDK is currently loading Flags | ||
The `useFeatureFlagsLoading` hook returns a boolean value indicating whether the SDK is currently loading Flags | ||
from the server. | ||
@@ -287,2 +287,34 @@ | ||
### `useFeatureFlagsClient` | ||
The React Client SDK internally uses the Javascript Client SDK to communicate with Harness. Sometimes it might be useful | ||
to be able to access the instance of the Javascript Client SDK rather than use the existing hooks or higher-order | ||
components (HOCs). The `useFeatureFlagsClient` hook returns the current Javascript Client SDK instance that the React | ||
Client SDK is using. This instance will be configured, initialized and have been hooked up to the various events the | ||
Javascript Client SDK provides. | ||
```typescript jsx | ||
import { | ||
useFeatureFlagsClient, | ||
useFeatureFlagsLoading | ||
} from '@harnessio/ff-react-client-sdk' | ||
// ... | ||
function MyComponent() { | ||
const client = useFeatureFlagsClient() | ||
const loading = useFeatureFlagsLoading() | ||
if (loading || !client) { | ||
return <p>Loading...</p> | ||
} | ||
return ( | ||
<p> | ||
My flag value is: {client.variation('flagIdentifier', 'default value')} | ||
</p> | ||
) | ||
} | ||
``` | ||
### `ifFeatureFlag` | ||
@@ -385,2 +417,31 @@ | ||
### `withFeatureFlagsClient` | ||
The React Client SDK internally uses the Javascript Client SDK to communicate with Harness. Sometimes it might be useful | ||
to be able to access the instance of the Javascript Client SDK rather than use the existing hooks or higher-order | ||
components (HOCs). The `withFeatureFlagsClient` HOC wraps your component and adds `featureFlagsClient` as additional | ||
prop. `featureFlagsClient` is the current Javascript Client SDK instance that the React Client SDK is using. This | ||
instance will be configured, initialized and have been hooked up to the various events the Javascript Client SDK | ||
provides. | ||
```typescript jsx | ||
import { withFeatureFlagsClient } from '@harnessio/ff-react-client-sdk' | ||
// ... | ||
function MyComponent({ featureFlagsClient }) { | ||
if (featureFlagsClient) { | ||
return ( | ||
<p> | ||
Flag1's value is {featureFlagsClient.variation('flag1', 'no value')} | ||
</p> | ||
) | ||
} | ||
return <p>The Feature Flags client is not currently available</p> | ||
} | ||
const MyComponentWithClient = withFeatureFlagsClient(MyComponent) | ||
``` | ||
## Testing with Jest | ||
@@ -387,0 +448,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54923
47
543
489