An open API service indexing awesome lists of open source software.

https://github.com/fdaciuk/react-ff

Feature Flag component for React
https://github.com/fdaciuk/react-ff

feature-flag feature-toggle hacktoberfest react typescript

Last synced: about 1 month ago
JSON representation

Feature Flag component for React

Awesome Lists containing this project

README

        


React Feature Flag

# Welcome to React Feature Flag 👋


Version

Documentation


Maintenance


License: MIT


Twitter: fdaciuk

> Type safe Components to create Feature Flags (or Feature Toggle) with React.js

## Install

```sh
yarn add @fdaciuk/react-ff
```

## Usage

First of all, we have to create our componentes using `createFeatureFlag` function.
Create a new file (e.g. `src/feature-flag.tsx`) with this content:

```ts
import { createFeatureFlag } from '@fdaciuk/react-ff'

export type Flags =
| 'NEW_HEADER'
| 'NEW_FOOTER'

const { FF, FFProvider } = createFeatureFlag()
export { FF, FFProvider }
```

Now, on top of your app, import `FFProvider` from `src/feature-flag.tsx`, and pass all the flags your app will use, following the shape:

```ts
const flags = {
NEW_HEADER: true,
NEW_FOOTER: false,
}
```

In the above example, the user has access to something that should be rendered by the flag `NEW_HEADER`, but not by the flag `NEW_FOOTER`.

Usage of `FFProvider`:

```tsx
function App () {
const flags = {
NEW_HEADER: true,
NEW_FOOTER: false,
}

return (



)
}
```

Now, anywhere on your app, you can use the `FF` component to make the feature flag (or feature toggle):

```tsx
function TheRestOfMyApp () {
return (
<>
}>

} />
>
)
}

function NewHeader () {
return (
New header
)
}

function OldHeader () {
return (
Old header
)
}

function NewFooter () {
return (
New footer
)
}
```

The `flag` prop is type safe, and will only accept flags from type `Flags`, passed for `createFeatureFlag` function.

The `children` is optional. You can pass a children when you want to render a fallback component, whether flag is disabled (`false`).

## Author

👤 **Fernando Daciuk - @fdaciuk**

* Website: https://daciuk.dev
* Twitter: [@fdaciuk](https://twitter.com/fdaciuk)
* Github: [@fdaciuk](https://github.com/fdaciuk)
* LinkedIn: [@fdaciuk](https://linkedin.com/in/fdaciuk)

## Credits

Logo by [@vmarcosp](https://github.com/vmarcosp) ♥️

## 🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/fdaciuk/react-ff/issues). You can also take a look at the [contributing guide](https://github.com/fdaciuk/react-ff/blob/master/CONTRIBUTING.md).

## Show your support

Give a ⭐️ if this project helped you!

## 📝 License

Copyright © 2021 [Fernando Daciuk - @fdaciuk](https://github.com/fdaciuk).

This project is [MIT](https://github.com/fdaciuk/react-ff/blob/master/LICENSE.md) licensed.