1.1 KiB
1.1 KiB
id, title, description
| id | title | description |
|---|---|---|
| createPlugin-feature-flags | createPlugin - feature flags | Documentation on createPlugin - feature flags |
The featureFlags object passed to the register function makes it possible
for plugins to register Feature Flags in Backstage for users to opt into. You
can use this to split out logic in your code for manual A/B testing, etc.
Here's a code sample:
import { createPlugin } from '@backstage/core';
export default createPlugin({
id: 'welcome',
register({ featureFlags }) {
featureFlags.register('enable-example-feature');
},
});
Using with useApi
To inspect the state of a feature flag inside your plugin, you can use the
FeatureFlagsApi, accessed via the featureFlagsApiRef. For example:
import React, { FC } from 'react';
import { Button } from '@material-ui/core';
import { featureFlagsApiRef, useApi } from '@backstage/core';
const ExamplePage = () => {
const featureFlags = useApi(featureFlagsApiRef);
return (
<div>
<MyPluginWidget>
{ featureFlags.isActive('enable-example-feature') && <ExperimentalPluginWidget> }
</div>
);
};