LaunchDarkly is a feature flag management platform that allows for simple control of flags across multiple environments, providing developers the ability to non-ironically test in production. LaunchDarkly supports most popular web languages, and there are a bunch of 3rd party libraries out there to make life easier as well. For React applications, I've tried a few different routes for handling client side feature flags, each with their own trade off between simplicity and flexibility.
LaunchDarkly component, throw your new functionality in a
FeatureFlag component, and you're good to go. As expected though, the price of this simplicity is the difficulty implementing custom logic.
Another great option is LaunchDarkly's own React SDK. This library provides a set of higher order components that initialize the LaunchDarkly client and then pass the flags in as
props wherever needed. One big benefit of this library is that the
ldClient is passed as
props along with the flags, allowing direct access to the client and all accompanying functionality. This library is a little less plug-and-play than TrueCar's, but the easy direct access to the client allows for easier implementation of custom logic.
FeatureFlag component for easy conditional rendering and a HOC for passing in the client and flags to whatever component needs them. When rolling your own, there is additional effort required to configure the flag change subscriptions which the above libraries do automatically, and of course there is more work in maintaining a custom implementation as opposed to using a library.
In general, I'll probably stick with LaunchDarkly's React SDK for production applications, unless custom client initialization logic or event handling is necessary.
Recently I started working with LaunchDarkly flags within React apps again, so I decided to revisit this post and reminisce about old times. In the nearly two years since this post was written, LaunchDarkly has revamped their own React SDK, including support for hooks and simplifying the overall API. There's also been a host of new supporting libraries including a Gatsby plugin and a (experimental) jest testing library. LaunchDarkly's offerings really are a pleasure to use, and I probably wouldn't use any other library at this point.
Last Updated On: Feb 07, 2021