All Projects → fvoordeckers → react-unleash-flags

fvoordeckers / react-unleash-flags

Licence: other
React Component for Gitlab or Unleash Feature Flags

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-unleash-flags

unleash-client-php
Unleash client SDK for PHP
Stars: ✭ 24 (-33.33%)
Mutual labels:  gitlab, feature-flags, unleash
unleash-client-ruby
Unleash client SDK for Ruby
Stars: ✭ 43 (+19.44%)
Mutual labels:  feature-flags, unleash
Unleash
Unleash is the open source feature toggle service.
Stars: ✭ 4,679 (+12897.22%)
Mutual labels:  feature-flags, unleash
gitlabr
An R client for the GitLab API
Stars: ✭ 31 (-13.89%)
Mutual labels:  gitlab
YappyGitLab
A GitLab monitor bot for Discord
Stars: ✭ 51 (+41.67%)
Mutual labels:  gitlab
Git-for-bio-scientists
Presentation about digital lab journalling with Git
Stars: ✭ 30 (-16.67%)
Mutual labels:  gitlab
MigrateGitlabToGogs
Migrate repositories from Gitlab to Gogs or Gitea
Stars: ✭ 49 (+36.11%)
Mutual labels:  gitlab
js-client-sdk
LaunchDarkly Client-side SDK for Browser JavaScript
Stars: ✭ 93 (+158.33%)
Mutual labels:  feature-flags
DoAnFullstack-ui
Currently on Offline mode for saving budget
Stars: ✭ 20 (-44.44%)
Mutual labels:  gitlab
CVE-2021-22205
GitLab CE/EE Preauth RCE using ExifTool
Stars: ✭ 165 (+358.33%)
Mutual labels:  gitlab
gitlabby-dockerish-laravel
What happens when you Dockerize your Laravel testing environment and throw it at Gitlab CI?
Stars: ✭ 33 (-8.33%)
Mutual labels:  gitlab
gitcolombo
🧬 Extract and analyze contributors info from git repos
Stars: ✭ 55 (+52.78%)
Mutual labels:  gitlab
OctoPrint-GitFiles
With this plugin, you can use a github/gitlab repository for keeping your OctoPrint Files collection up-to-date.
Stars: ✭ 28 (-22.22%)
Mutual labels:  gitlab
10-days-of-git-and-github
asabeneh.github.io/10-days-of-git-and-github/
Stars: ✭ 786 (+2083.33%)
Mutual labels:  gitlab
doorkeeper
A Feature Toggle for PHP
Stars: ✭ 16 (-55.56%)
Mutual labels:  feature-flags
go-zero-looklook
🔥基于go-zero(go zero) 微服务全技术栈开发最佳实践项目。Develop best practice projects based on the full technology stack of go zero (go zero) microservices.
Stars: ✭ 2,691 (+7375%)
Mutual labels:  gitlab
dependency-update-maven-plugin
A Maven plugin that creates merge requests for dependency updates.
Stars: ✭ 23 (-36.11%)
Mutual labels:  gitlab
phpcs-gitlab
Gitlab Report for PHP_CodeSniffer (display the violations in the Gitlab CI/CD Code Quality Report)
Stars: ✭ 29 (-19.44%)
Mutual labels:  gitlab
posthog-node
Official PostHog Node library
Stars: ✭ 18 (-50%)
Mutual labels:  feature-flags
gitlab-ci-variables-cli
CLI tool to allow setting bulk project variables on Gitlab CI
Stars: ✭ 38 (+5.56%)
Mutual labels:  gitlab

⚠️ Deprecation Notice ⚠️

This library is deprecated since Unleash implemented a similar alternative and has an official Unleash SDK for React now. This official SDK also works with their Unleash proxy, which is the better solution in terms of security.



React Unleash Flags

React component for Unleash or GitLab Feature Flags. This library provides a custom hook and react components to use in JavaScript or TypeScript projects.

Installation

Using NPM:

npm i --save react-unleash-flags

Configuration

The following config is required in order to fetch te flags from your Unleash or GitLab instance:

  • appName (the name of the app you will be running. Eg.: 'production', 'staging')
  • host (the location of the Unleash api. Eg.: ht​tps://my-unleash-url.com/api/)
  • url (Deprecated! Use host instead)
  • uri (the uri of the Unleash api. Eg.: /client/features) (this could be different if you want to point to an Unleash Proxy instead)
  • instanceId (the unique Unleash instance ID)
  • extraHttpHeaders (OPTIONAL extra http headers passed to the fetch call. For example, an Authorization header)

This configuration can be provided as an env variabe. The environment variables are:

  • REACT_APP_FLAGS_CTX_APP_NAME
  • REACT_APP_FLAGS_CTX_HOST
  • REACT_APP_FLAGS_CTX_URL (Deprecated! Use REACT_APP_FLAGS_CTX_HOST instead)
  • REACT_APP_FLAGS_CTX_URI
  • REACT_APP_FLAGS_CTX_INSTANCE_ID

The configuration can also be provide as a dict. (see examples below)

<FlagsProvider> with config in env vars

import React from 'react';
import ReactDOM from 'react-dom';
import { FlagsProvider } from 'react-unleash-flags';
import App from './App';

const root = document.getElementById('root');

if (root != null) {
    ReactDOM.render((
        <FlagsProvider>
            <App />
        </FlagsProvider>
    ), cakeRoot);
}

<FlagsProvider> with config in code

import React from 'react';
import ReactDOM from 'react-dom';
import { FlagsProvider } from 'react-unleash-flags';
import App from './App';

const root = document.getElementById('root');

// we can also define the config in code instead of using env vars
const flagConfig = {
    appName: 'production',
    host: 'https://...',
    uri: '/client/features',
    instanceId: '...',
    extraHttpHeaders: {
        Authorization: 'token123'
    }
};

// or if env vars are used for Unleash Flags settings, they can be combined 
// these settings will be appended to the settings from the env variables
const flagConfig = {
    extraHttpHeaders: {
        Authorization: 'token123'
    }
};

if (root != null) {
    ReactDOM.render((
        <FlagsProvider config={flagConfig} >
            <App />
        </FlagsProvider>
    ), cakeRoot);
}

Usage

Make sure you've setup the <FlagsProvider> correctly.

Custom useFlag Hook

// load the flag using the useFlag hook
const flag = useFlag(name);

// a flag that does not exist will return undefined
if (flag && flag.enabled) {
    ...
}

React <FeatureFlag> component

Attributes:

  • name: string - the name of the flag
  • defaultValue (optional, default=false): boolean - the value when the flag does not exist or when it is still loading
  • invert (optional, default=false): boolean - if true, the child elements will render when the feature is disabled

The <FeatureFlag> component can handle both JSX and a function as child elements:

<FeatureFlag name="test-flag">
    hello, this flag is enabled
</FeatureFlag>

<FeatureFlag name="test-flag" invert={true}>
    hello, this flag is disabled
</FeatureFlag>

<FeatureFlag name="test-flag">
    {(flag) => { console.log(flag); }}
</FeatureFlag>

Links

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].