# @feijoa/react

> Feature development made easy

Latest version **3.2.0** (published 2023-01-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install @feijoa/react
pnpm add @feijoa/react
yarn add @feijoa/react
bun add @feijoa/react
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2023-01-06 |
| First published | 2022-03-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 21.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Stretch Codes Ltd |
| Maintainers | stretch0, feijoa-dev |
| Keywords | React, Optimizely, Flagsmith, launchdarkly, launch, toggles, feature, flag, feature toggle, feature flag, continuous deployment |

## Links

- npm: https://www.npmjs.com/package/@feijoa/react
- Repository: https://github.com/feijoa-dev/feijoa-react
- Homepage: https://github.com/feijoa-dev/feijoa-react#readme
- Issues: https://github.com/feijoa-dev/feijoa-react/issues
- npm.io page: https://npm.io/package/@feijoa/react

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.2.0 (latest) — 2023-01-06
- 3.1.0 — 2023-01-06
- 3.0.0 — 2023-01-05
- 2.2.8 — 2023-01-05
- 2.2.7 — 2022-10-27
- 2.2.6 — 2022-10-15
- 2.2.5 — 2022-10-15
- 2.2.4 — 2022-10-15
- 2.2.0 — 2022-05-23
- 2.1.0 — 2022-05-23
- 2.0.3 — 2022-05-23
- 2.0.2 — 2022-05-22
- 2.0.1 — 2022-05-22
- 1.4.0 — 2022-04-19
- 1.3.0 — 2022-04-02
- … 7 more at https://npm.io/package/@feijoa/react/versions

## README

# @feijoa/react

[![NPM](https://img.shields.io/npm/v/@feijoa/react.svg)](https://www.npmjs.com/package/@feijoa/react) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

- [What is Feijoa](#what-is-feijoa)
- [Problem](#problem)
- [Install](#install)
- [Usage](#usage)
- [Props](#props)
- [Overrides](#overrides)

## What is Feijoa?
A comprehensive React feature flag library providing reusable components and hooks along with easy override features so internal, non-technical users can toggle them off with ease without effecting anybody else.

## Problem

It can be finicky managing feature flags across multiple environments and is only exacerbated when you need to enable a feature for one user or for a one off i.e. a QA who needs to test or when you want demo a feature for review. 

Normally this would require toggling a feature flag in an environment variable and re-running a build. This can take time depending on your CI or maybe you have to do a release to get the changes deployed.

Now you to don't have to worry about any of this and you can toggle features in your browser, without any code deploys! Simply override a feature flag with a query param, cookie or local storage. They can even be overridden with env variables if you want certain builds to not have a feature.

## Install

```bash
npm install --save feijoa-react
```
or
```bash
yarn add feijoa-react
```

## Usage

### Component
```tsx
import React, { Component } from 'react'

import { Feature } from "@feijoa/react";

const Example = () => {
  return (
    <Feature name="MY_FEATURE">
      <MyFeature />
    <Feature>
  );
}
```

### Hook

```tsx
import React, { Component } from 'react'

import { useFeature } from "@feijoa/react";

const Example = () => {
  const showFeature = useFeature({
    name: "MY_FEATURE"
  });

  return (
    showFeature ? <MyFeature /> : null
  );
}
```

You can use the `enabled` prop to conditionally enable your feature

```tsx
import React, { Component } from 'react'

import { useFeature } from "@feijoa/react";

const Example = () => {
  const showFeature = useFeature({
    name: "MY_OTHER_FEATURE",
    enabled: true
  });

  return (
    showFeature ? <MyFeature /> : null
  );
}
```

## Props

| Prop            | Type        | Description                                                       | Required | default Value  |
| ------------    | ----------- | -------------------------------------------------------           | ---------| ---------|
| `name`          | string      | Name of your feature flag (used for overrides)                    | true     | N/A      |
| `enabled`       | boolean     | `true` = show, `false` = hide                                     | false    | `false`    |
-------------------------

## Overrides

Sometimes it's useful for some users to be able override feature flags on their local browser. This is particularly useful if you want a feature disabled for the public but need to enable it for a one person to test. E.g. for the QA tester or a product owner etc.

This can be done either via a query string or via a setting a cookie

*NOTE: query string or cookie keys must match the `name` you pass into the Feijoa component or hook props*

### Query string

```sh
 // enable
 https://example.com?MY_FEATURE=true

 // disable
 https://example.com?MY_FEATURE=false
```

### Local Storage

```js
// enable
localStorage.setItem('localStorage_flag_enabled', 'true');

// disable
localStorage.setItem('localStorage_flag_enabled', 'false');
```

### Cookie

```js
// enable
document.cookie = 'MY_FEATURE=true;'

// disable
document.cookie = 'MY_FEATURE=false;'
```

Environment Variables
```sh 
#.env
MY_FEATURE=true
# or if you're using create react app
REACT_APP_MY_FEATURE=true
# or if you're using Gatsby
GATSBY_MY_FEATURE=true
```

## License

MIT © [Feijoa Dev](https://github.com/feijoa-dev)

---
_Source: https://npm.io/package/@feijoa/react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
