IAmHughes / ld-react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LD-React

Simple app from create-react-app modified to showcase a red light / green light Feature Flag setup with LaunchDarkly. This can be further enhanced by leveraging targeting and a more compelling feature to easily do A/B testing, send specific users through specific code paths, etc.

red-light-green-light-example

How to use

In order to test this repostiory out locally, you can follow the following steps. Note: This guide assumes you have installed tooling such as git, node, and know how to clone a repository and make basic edits in code.

  1. Clone the repository locally
  2. Go to your LaunchDarkly Feature Flag Dashboard
  3. Create a new flag named trafficLight and enter the following information (see image below for reference)
    • key: trafficLight
    • Check the box for SDKs using Client-side ID
    • Flag variations: Boolean
    • Variation 1 - value: true, Name: Green Light
    • Variation 2 - value: false, Name: Red Light
    • Click Save flag

create-flag

  1. Within your local version of the repository, open the src/App.js file and edit the clientSideID value from YOUR-CLIENT-SIDE-ID to your actual client side SDK ID.
    • From your LaunchDarkly Account Settings page, select the project you created the flag in, then copy the Client-side ID and replace the YOUR-CLIENT-SIDE-ID string accordingly.

client-side-id

Note: The React SDK uses the Client-side ID, not the SDK key or the Mobile key.

  1. Ensure your terminal is in the root directory of the project and run npm install to install the repository dependencies, including the LaunchDarkly React SDK.
  2. Ensure your changes are saved, then run npm start
  3. Open your browser to localhost:3000
  4. You should notice the text stating "The flag is off" and a red circle below.
  5. From your LaunchDarkly Feature Flag Dashboard toggle the flag on and save your changes in the pop-up that appears. Note the app now has the text "The flag is on" and a green circle below.

About

License:MIT License


Languages

Language:JavaScript 43.8%Language:HTML 36.5%Language:CSS 19.7%