truflag-launchdarkly-react-client-sdk
v0.1.1
Published
LaunchDarkly-compatible React migration SDK powered by Truflag
Downloads
22
Readme
truflag-launchdarkly-react-client-sdk
LaunchDarkly-compatible React migration SDK powered by Truflag.
This package is intended for migration workflows where teams can swap the import and keep existing
LaunchDarkly React usage patterns (withLDProvider, asyncWithLDProvider, useFlags, useLDClient)
while evaluating flags and emitting metrics through Truflag.
Install
npm install truflag-launchdarkly-react-client-sdkExample
import { withLDProvider, useFlags, useLDClient } from "truflag-launchdarkly-react-client-sdk";
function App() {
const flags = useFlags();
const ldClient = useLDClient();
const checkoutEnabled = Boolean(flags.checkoutV2);
return (
<button
onClick={() => {
void ldClient?.track("checkout_clicked", { surface: "app" }, 1);
}}
>
{checkoutEnabled ? "New checkout" : "Legacy checkout"}
</button>
);
}
export default withLDProvider({
clientSideID: process.env.NEXT_PUBLIC_TRUFLAG_CLIENT_KEY!,
context: { kind: "user", key: "user-123", plan: "pro" },
})(App);