New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

use-feature-flags

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

use-feature-flags

React hooks to fetch flags from Feature Flags API

unpublished
latest
Source
npmnpm
Version
1.3.3
Version published
Maintainers
1
Created
Source

use-feature-flags

/!\ COMING SOON !!! You need to use the Feature flags API to use this hook.

Usage

Install

npm i use-feature-flags

Implementation

By default, if a flag cannot be fetched, it will be false.

The Feature Flag API uses the User-Agent header from the request to determine if the user has access to the feature.

import { FlagsProvider, useFlags } from 'use-feature-flags'

function App() {
    return <FlagsProvider
        config={{
            apiUrl: 'your-self-hosted-api-url',
            apiServiceId: 'the-service-id',
            apiAuthorization: 'the-authorization-key-you-defined-in-the-api',
            debug: true // optional, default: false
        }}
    >
        <MyComponent/>
    </FlagsProvider>
}

function MyComponent() {
    const { isFlagOn, flags, getFlag } = useFlags()

    /**
     * Two usages :
     * - with getFlag(key) => returns the flag object with the value and the enabled status
     * - with isFlagOn(key) => returns the enabled status
     */
    return <div>
        {isFlagOn('my-welcome-message') && <p>{getFlag('my-welcome-message').value}</p>}
        {isFlagOn('my-flag-key') ? <p>Hello world !</p> : <p>This feature is off</p>}
    </div>
}

Reference

// FlagsProvider
interface UseFlagsParams {
    config: {
        apiUrl: string
        apiServiceId: string
        apiAuthorization: string,
        debug?: boolean
    }
}

// useFlags()
interface UseFlagsHook {
    // List all flags from the specified services
    flags: Flag[]
    // Return a specified flag
    getFlag: (key: string) => Flag | undefined
    // Return the enabled status of a specified flag
    isFlagOn: (key: string) => boolean
}

interface Flag {
    key: string
    enabled: boolean
    value: string
}

FAQs

Package last updated on 08 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts