JSPM

  • Created
  • Published
  • Downloads 55119
  • Score
    100M100P100Q208070F
  • License Apache-2.0

OpenFeature React SDK

Package Exports

  • @openfeature/react-sdk

Readme

OpenFeature Logo

OpenFeature React SDK

Specification
codecov

OpenFeature is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.

🧪 This is SDK is experimental.

Here's a basic example of how ot use the current API with flagd:

import logo from './logo.svg';
import './App.css';
import { OpenFeatureProvider, useFeatureFlag, OpenFeature } from '@openfeature/react-sdk';
import { FlagdWebProvider } from '@openfeature/flagd-web-provider';

const provider = new FlagdWebProvider({
  host: 'localhost',
  port: 8013,
  tls: false,
  maxRetries: 0,
});
OpenFeature.setProvider(provider)

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

function Page() {
  const booleanFlag = useFeatureFlag('new-welcome-message', false);
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        {booleanFlag ? <p>Welcome to this OpenFeature-enabled React app!</p> : <p>Welcome to this React app.</p>}
      </header>
    </div>
  )
}

export default App;