1.0.20 • Published 2 years ago

f-beta-react-sdk v1.0.20

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Using the React SDK

  1. Install the Fana React SDK in your project by running npm i fana-react-sdk
  2. Import the following files into your React project's App.js file

import { FanaConfig, FanaProvider } from 'fana-react-sdk'

  1. Use the FanaSDK's FanaConfig class constructor to instantiate a config object. This constructor takes three arguments:
  • SDK key (from your dashboard's settings page)
  • The address of your Flag Bearer
  • User Context: This is an object containing the attributes pertaining to the current user
const config = new FanaConfig('sdk_key_0', 'http://localhost:3001', { userId: 'jjuy', beta: true })
                                   ^SDK Key     ^Flag Bearer Address      ^User Context Object
  1. Next, wrap your outermost component in the <FanaProvider> component. You will pass in your newly created config instance as an argument to the config prop.
function App() {
  return (
    <FanaProvider config={config}>
      <main>
        <Header />
        <Body />
      </main>
    </FanaProvider>
  );
}

Now you can evaluate flags in any component you wish! Make sure to import React's useContext hook, as well as the FanaContext.

Within your component, import React's useContext as well as Fana's FanaContext. Invoke useContext(FanaContext). This will provide you with the client instance which has access to the evaluateFlag method.

const fanaClient = useContext(FanaContext);
const betaHeader = fanaClient.evaluateFlag("beta_header", true);

The evaluateFlag method takes two arguments: the flag key that you wish to evaluate, and an optional argument for a default value.

The optional argument will be false if no value is provided. This optional argument will only apply in cases where it cannot determine the value of the provided flag key. This may happen when connection with the Flag Bearer fails, or if the flag key simply does not exist.

evaluateFlag returns true or false depending on how the user context was evaluated. Use this to determine what experience this particular user should receive.

const experienceText = betaHeader ? "beta" : "regular";

return <h1>Welcome to the {experienceText} experience!</h1>;
1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago