1.2.1 • Published 5 years ago

@rqbazan/featflag v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

🌌 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 />}
    </>
  )
}

withFF(Component)

Returns a wrapper component which receive hasFeature function as prop.

import { withFF } from '@rqbazan/featflag'

const AwesomeComponent = props => {
  const { hasFeature } = props

  const hasThatFeature = hasFeature('some-feature-name')

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

export default withFF(AwesomeComponent)

🍕 LICENSE 🍕

MIT

1.2.1

5 years ago

1.2.0

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago