Skip to main content

Using the JavaScript SDK

appflags GitHub Repo stars

Getting a Feature Flag

To retrieve a Feature Flag, use the getFlag function:

AppFlags.getFlag("flag_key", flag => {
const value = flag.value;
});

Subscribing to a Feature Flag

To subscribe to a Feature Flag and get realtime updates, use the onFlagChanged function:

AppFlags.onFlagChanged("flag_key", flag => {
const value = flag.value;
});

When the feature flag is updated, onFlagChanged will be invoked immediately.

Note that onFlagChanged resolves with the current Feature Flag, so there is no need to call getFlag as well.

Flag Properties

The Flag object contains the following properties:

  • key: the key identifier for the Feature Flag
  • value: the value of the active Variation, either a boolean, number, or string

Example Repository

For a full example of using AppFlags in a JavaScript application, see https://github.com/AppFlags/example-javascript.