Simple client side toggle flags.
- jQuery like API for getter/setter
- Dev React component to set/unset flags
The FlagSwitcher
component helps toggling the flags.
import flag from 'cozy-flags'
if (flag('my-feature')) {
enableMyFeature()
}
The FlagSwitcher
shows all flags in use and displays all
flags in use.
import flag, { FlagSwitcher } from 'cozy-flags'
if (process.env.NODE_ENV !== 'production'
&& flag('switcher') === undefined) {
flag('switcher', true) // set default flag in dev mode
}
const App = () => {
return (
<div>
{ flag('switcher') && <FlagSwitcher /> }
<MyApp />
</div>
)
}
It is possible to handle flags enabled at build time. Your app should just
provide a global __ENABLED_FLAGS__
array with flag names that should be
enabled. If such a global exists, cozy-flags
will iterate on the array and
enable all the flags it contains when it is imported.