2.0.0 • Published 5 years ago
@spacemakerai/ldclient-react v2.0.0
ldclient-react
React library to make launch darkly integration easier.
Changelog: CHANGELOG.md
Usage
First, install the dependency:
$ yarn add @spacemakerai/ldclient-react
Use the LaunchDarklyProvider
with the correct clientSideId
found in the LaunchDarkly dashboard.
// @flow
import React from "react";
import MyReactApp from "./MyReactApp";
import { LaunchDarklyProvider } from "@spacemakerai/ldclient-react";
<LaunchDarklyProvider
clientSideId={process.env.REACT_APP_LD_CLIENT_SIDE_ID || ""}
>
<MyReactApp />
</LaunchDarklyProvider>;
Then use the withLaunchDarkly
(HOC) in some child component to get the LaunchDarkly client.
This client will already be initialized by the LaunchDarklyProvider
.
// @flow
import React from "react";
import { withLaunchDarkly, type LDClient } from "@spacemakerai/ldclient-react";
type Props = {
ldclient: LDClient
};
class CoolComponent extends React.Component<Props> {
render() {
if (this.props.ldclient.variation("fancy-new-feature", false)) {
return <div>Fancy new stuff</div>;
}
return <div>Boring old stuff</div>;
}
}
export default withLaunchDarkly(CoolComponent);
LaunchDarkly client SDK: https://docs.launchdarkly.com/docs/js-sdk-reference
Deploying
First, update CHANGELOG.md
with the recent changes. Add the changes to the
changelog to the git stage. Then, create a new version and publish to npm:
$ yarn publish
Hacking
Install all dependencies:
$ yarn
Run tests:
$ yarn test
Check formatting:
$ yarn prettier