0.0.10 • Published 1 year ago

@flagbase/react-client-sdk v0.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Flagbase React Client SDK

This is the official React client-side SDK for Flagbase. With this SDK, you can use lagbase feature flags and experiments in your React applications.

Installation

You can install the package using npm:

$ npm install @flagbase/react-client-sdk

or yarn:

yarn add @flagbase/react-client-sdk

Usage

  1. Import the SDK

To use the SDK, import it at the top of your file:

import FlagbaseProvider, { useFeatureFlag } from "@flagbase/react-client-sdk";
  1. Wrap your app in the FlagbaseProvider

Wrap your app with the FlagbaseProvider component to enable the SDK to communicate with the Flagbase service. Pass in the clientKey and optionally, identity and opts props:

function App() {
  return (
    <FlagbaseProvider
      clientKey="YOUR_CLIENT_KEY"
      identity={{ identifier: "USER_ID", traits: { age: 25 } }}
      opts={{ debug: true }}
    >
      <MyApp />
    </FlagbaseProvider>
  );
}
  1. Use feature flags with useFeatureFlag

Use the useFeatureFlag hook to get the value of a feature flag. Pass in the flagKey and defaultVariationKey props:

function MyComponent() {
  const isFeatureEnabled = useFeatureFlag("MY_FEATURE", false);

  return <div>{isFeatureEnabled ? "Feature enabled!" : "Feature disabled."}</div>;
}
  1. Use the Flagbase client instance with useFlagbaseClient

Use the useFlagbaseClient hook to get access to the Flagbase client instance:

function MyComponent() {
  const flagbaseClient = useFlagbaseClient();

  // Do something with the client instance
}

Contributing

Contributions are welcome! If you have any bug reports, feature requests, or pull requests, please open an issue or submit a pull request on GitHub.

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago