@feijoa/react
source link: https://www.npmjs.com/package/@feijoa/react
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
@feijoa/react
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
As code bases grow larger, it can be unclear what code is part of a feature and if it should be enabled. Some feature flags are also unclear if they are part of some other config or just simply a conditional statement. Having a verbose feature flag component or hook helps distinguish them from the rest of your code.
Old feature flags often get left in code bases as teams are unsure if they are still being used or not. Having a common component to manage features makes it much easier to find them all when the time comes to remove them.
Install
npm install --save feijoa-react
yarn add feijoa-react
Usage
#.env
FEATURE_ENABLED=true
# or if you're using create react app
REACT_APP_FEATURE_ENABLED=true
Component
import React, { Component } from 'react'
import { Feature } from "@feijoa/react";
const Example = () => {
return (
<Feature envVar="FEATURE_ENABLED">
<MyFeature />
<Feature>
);
}
import React, { Component } from 'react'
import { useFeature } from "@feijoa/react";
const Example = () => {
const showFeature = useFeature({
enabled: true
});
return (
showFeature ? <MyFeature /> : null
);
}
Props
Prop | Type | Description | Required |
---|---|---|---|
enabled |
boolean |
true = show, false = hide |
false |
envVar |
string | Maps to a environment variable | false |
defaultValue |
boolean | Sets the initial value of your feature when your app loads | 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 envVar
name you pass into the Feijoa component or hook
Query string
// enable
https://example.com?my_feature=true
// disable
https://example.com?my_feature=false
Cookie
// enable
document.cookie = 'my_feature=true;'
// disable
document.cookie = 'my_feature=false;'
License
MIT © Feijoa Dev
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK