Skip to main content

OpenFeature Provider for React

Integrate your React applications with Harness FME using the React OpenFeature ProviderAn OpenFeature Provider wraps the Harness FME SDK, acting as a bridge between the OpenFeature SDK and the FME SDK. It translates OpenFeature function calls into operations handled by the FME SDK, which communicates with Harness services to evaluate flags and retrieve configuration updates., a standardized, vendor-agnostic feature flagging API. This provider implements the OpenFeature specification and bridges the OpenFeature SDK with the Harness FME Browser SDK.

This page walks you through installing, configuring, and using the React OpenFeature provider to evaluate feature flagsA feature flag is a conditional toggle in Harness FME that enables or disables specific functionality without deploying new code. It allows for controlled feature rollouts, A/B testing, and quick rollbacks if issues arise. in your React applications.

Prerequisites

Before you begin, ensure you have the following:

  • A valid Harness FME SDK key for your application
  • An React 17+ application using evaluation hooks
  • Access to your application's package.json file to add the provider dependency

Version compatibility

ComponentMinimum Version
React≥ 17
@splitsoftware/openfeature-web-split-provider≥ 1.0.0
Harness FME Browser SDK≥ 10.x
OpenFeature React SDK≥ 0.1.0

Install the provider and dependencies

Add the Harness FME OpenFeature provider dependency to your application's package.json file.

npm i @openfeature/react-sdk @splitsoftware/splitio-browserjs @splitsoftware/openfeature-web-split-provider

Initialize the provider

The Harness FME OpenFeature provider requires your Harness FME Browser SDK key and a targeting keyA unique identifier used to target specific users or entities when evaluating feature flags. It helps determine which variation of a flag should be served based on predefined rules and conditions..

import { OpenFeature } from '@openfeature/react-sdk';
import { OpenFeatureSplitProvider } from '@splitsoftware/openfeature-web-split-provider';
import { DebugLogger, SplitFactory } from '@splitsoftware/splitio-browserjs';

const splitFactory = SplitFactory({
core: {
authorizationKey: '<YOUR_CLIENT_SIDE_SDK_KEY>',
key: 'TARGETING_KEY'
}
})
const openFeatureProvider = new OpenFeatureSplitProvider(splitFactory);

OpenFeature.setProvider(openFeatureProvider);

function App() {
return (
<OpenFeatureProvider>
<Page></Page>
</OpenFeatureProvider>
);
}

Evaluate feature flags using evaluation hooks

Specify the feature flag key and a default value in useFlag so your application has a predictable fallback while the flag value loads.

import { useFlag } from '@openfeature/react-sdk';

function Page() {
// Use the "query-style" flag evaluation hook, specifying a flag-key and a default value.
const { value: showNewMessage } = useFlag('new-message', true);
return (
<div className="App">
<header className="App-header">
{showNewMessage ? <p>Welcome to this OpenFeature-enabled React app!</p> : <p>Welcome to this React app.</p>}
</header>
</div>
)
}

For more information, go to the Harness FME Web OpenFeature Provider GitHub repository.