This guide explains how to configure your Salesforce environment to use the LaunchDarkly JavaScript or React Web client-side SDKs in Lightning Web Components (LWCs).
Salesforce Lightning Web Components are an implementation of standard web components that allow you to leverage HTML, CSS, and JavaScript in a lightweight framework. To learn more, read Introducing Lightning Web Components.
The example code in this guide is extracted snippets. We show it here as if it is being used in a JavaScript class.
To complete this guide, you must have the following prerequisites:
To begin, find the latest version under Releases in the JavaScript SDK GitHub repository. Then download the desired version from https://unpkg.com/launchdarkly-js-client-sdk@<VERSION>/dist/ldclient.min.js.
Next, set up your Salesforce environment. To do this:
https://*.launchdarkly.com as a CSP Trusted Site, under Manage CSP Trusted SitesIn the JavaScript file of your Lightning Web Component, import the static resource:
Then, load the imported script for usage in the file, using the Lightning Web Component Platform Resource Loader:
Finally, initialize the LaunchDarkly client:
You can access the flag value using a JavaScript getter method:
To learn more, read LWC Data Binding. You can then use HTML to allow feature flags to control your user interface (UI) display.
Here is an example of an LWC HTML snippet:
In this guide, we discussed how to use the LaunchDarkly JavaScript and React Web client-side SDKs in Lightning Web Components. This allows you to leverage HTML, CSS, and JavaScript in a lightweight framework.