Skip to content

feat: update OpenFeature React example #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

missionmike
Copy link
Contributor

@missionmike missionmike commented Jul 9, 2025

Description

This PR updates the OpenFeature React example for compatibility with a new OpenFeature article.

Notable Changes

  • Uses environment variable for the client key.
  • Uses environment variable for the API endpoint in order to allow users to test with local Flagsmith docker compose instances (or their own hosted version).
  • Updates dependencies.
  • Removes unused dependencies.
  • Swaps out react-scripts for Vite.

Testing React App

Setup

  1. Checkout branch, open the open-feature/react/ folder in your IDE.
  2. Copy .env.example to .env file.
  3. Use your own Flagsmith client-side environment ID in the REACT_APP_FLAGSMITH_ENVIRONMENT_ID property in the .env file:
image

Note: leave REACT_APP_FLAGSMITH_API as-is, unless you're testing with a different Flagsmith API endpoint.

  1. Run nvm use to use the Node version located in .nvmrc (v22). If you do not have nvm installed, visit here to install: https://github.com/nvm-sh/nvm
image
  1. Run npm i to install dependencies.
image

Flagsmith Setup

  1. Ensure you have a font_size feature set in Flagsmith with a numeric value. 16 is used in this example.

  2. Add a Segment Override for example_trait with a value of 1 and set the overridden value to 17.

image

Run the App

  1. Run npm start to start the dev server.
image

Open the browser, and you should see the following:

image

Click the "Login" button, which will set the example_trait property in the Flagsmith provider to 1, and you should see a 17 as the font_size value:

image

Testing checkEnv.js

Within the npm start script in package.json, there's a preliminary run to execute checkEnv.js first. This script checks if the .env.example file is properly copied and configured during initial setup. This is meant to help ensure people are reminded to set up this .env file correctly before they attempt to run this demo.

If the .env.example file is not copied to .env yet, and you run npm start, you should see this error:

image

If .env.example is copied to .env, but the Flagsmith environment ID is not updated, you should see this error:

image

TODO

  • Update React and other package major versions.
  • Test identities locally.
  • Update styling of the demo app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For prettier formatting (automatic line wrap) on .md files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I grabbed the favicon from the main Flagsmith repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config was generated by viject: https://github.com/bhbs/viject

@missionmike missionmike marked this pull request as ready for review July 11, 2025 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant