@rqbazan/featflag
A small and modern ReactJS library to use the feature toggling principle
Last updated 2 months ago by rqbazan .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rqbazan/featflag 
SYNC missed versions from official npm registry.

???? FeatFlag ????

A small and modern ReactJS library to use the feature toggling principle

???? Installation ????

$ yarn add @rqbazan/featflag

or

$ npm install --save @rqbazan/featflag

???? Components and Hooks ????

<FlagProvider />

Uses the FlagContext.Provider to easily pass down the features. Note, this should be always used in the root app file.

import { FlagProvider } from '@rqbazan/featflag'
import App from './app'

// this should be come from an external service
const features = [
  'feature-a',
  'feature-b',
  'feature-c',
  ...
]

const Root = () => {
  return (
    <FlagProvider features={features}>
      <App />
    </FlagProvider>
  )
}

<Flag />

Render its children if the feature name passed as prop is in the provided context.

import { Flag } from '@rqbazan/featflag'

const AwesomeComponent = () => {
  return (
    <Flag featureName="some-feature-name">
      <h1>Hi there</h1>
    </Flag>
  )
}

Also support the render prop style

import { Flag } from '@rqbazan/featflag'

const AwesomeComponent = () => {
  return (
    <Flag featureName="some-feature-name">
      {enabled => {
        return enabled ? <span>????</span> : <span>????</span>
      }}
    </Flag>
  )
}

useFlag(featureName)

Returns true if the feature name passed as argument is in the provided context. Otherwise, false.

import { useFlag } from '@rqbazan/featflag'

const AwesomeComponent = () => {
  const hasThatFeature = useFlag('some-feature-name')

  return (
    <>
      <h1>My awesome app</h1>
      {hasThatFeature && <SomeComponent />}
    </>
  )
}

???? LICENSE ????

MIT

Current Tags

  • 1.1.1                                ...           latest (2 months ago)

9 Versions

  • 1.1.1                                ...           2 months ago
  • 1.1.0                                ...           2 months ago
  • 1.0.7                                ...           2 months ago
  • 1.0.6                                ...           2 months ago
  • 1.0.5                                ...           2 months ago
  • 1.0.4                                ...           3 months ago
  • 1.0.3                                ...           3 months ago
  • 1.0.2                                ...           3 months ago
  • 1.0.0                                ...           3 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 101
Dependencies (0)
None
Dev Dependencies (25)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |