npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@inovaebiz/inova-feature-flag

v1.1.7

Published

O Inova Feature Flag é uma biblioteca para React e React Native que permite configurar e acessar flags de recursos em seu aplicativo. Com ela, você pode facilmente definir as flags de recursos em um único lugar e acessá-las em todo o seu aplicativo usando

Downloads

6

Readme

Inova Feature Flag for React / React Native

Use inova-feature-flag in your React Native project. To do this, open the terminal and navigate to the root of your project. Then, execute the following command:

npm install @inovaebiz/inova-feature-flag

Or, if you prefer to use yarn:

yarn add @inovaebiz/inova-feature-flag

This will install the inova-feature-flag package and its dependencies in your project.

Configuration

Now that the inova-feature-flag package is installed, you need to configure it in your app. To do this, you need to:

Import InovaFeatureFlagProvider from inova-feature-flag and wrap your app with it, usually at the highest level of the component. Example:

import { InovaFeatureFlagProvider } from '@inovaebiz/inova-feature-flag'
import App from './App'

const MyApp = () => (
  <InovaFeatureFlagProvider
    sdkKey='your_sdk_key'
    options={{
      url: 'your_custom_url',
    }}
  >
    <App />
  </InovaFeatureFlagProvider>
)

export default MyApp

Remembering that the custom url you place has to bring data in this format:

{
  "success": true,
  "data": {
    "featureFlags": [
      {
        "key": "app:services",
        "value": true,
        "description": "Enable services"
      }
    ]
  }
}

And it also has to be an api in post that receives a bearer token in authorization by the header with the obligatory sdkKey inside the provider.

Usage

Now that InovaFeatureFlagProvider is configured in your app, you can use the useInovaFlag hook to access the feature flags in any component. To do this, import useInovaFlag from inova-feature-flag and call it with the feature flag key and default value, as shown in the example below:

import { useInovaFlag } from '@inovaebiz/inova-feature-flag'

const MyComponent = () => {
  const servicesEnabled = useInovaFlag('app:services:enabled', false)

  return <View>{servicesEnabled && <Text>Services are enabled</Text>}</View>
}

Note that by default, the return value of useInovaFlag is a boolean. However, you can specify a default value that is a string to indicate that the feature flag should be interpreted as a string. For example:

import { useInovaFlag } from '@inovaebiz/inova-feature-flag'

const MyComponent = () => {
  const theme = useInovaFlag('app:theme', 'light')

  return (
    <View>
      <Text>The current theme is {theme}</Text>
    </View>
  )
}

Typing

If you want to have strong typing for the feature flag keys and their value types, you can use the useInovaFlag generic typing feature. To do this, first define a type that describes the feature flag keys and their value types, as shown in the example below:

import { useInovaFlag } from '@inovaebiz/inova-feature-flag'

type FeatureFlagsKeys = {
  'app:services:enabled': boolean
  'app:theme': string
}

const MyComponent = () => {
  const servicesEnabled = useInovaFlag<FeatureFlagsKeys>('app:services:enabled', false)
  const theme = useInovaFlag<FeatureFlagsKeys>('app:theme', 'light')

  return (
    <View>
      {servicesEnabled && <Text>Services are enabled</Text>}
      <Text>The current theme is {theme}</Text>
    </View>
  )
}

In this example, the FeatureFlagsKeys type defines the feature flag keys and their value types. Then, when you use useInovaFlag, you specify FeatureFlagsKeys as the generic type to have strong typing for these keys.

Contributing

This package is private to the Inovaebiz organization, but we would love to have your contribution! If you want to contribute to this package, follow these steps:

  • Fork this repository to your GitHub account.
  • Create a branch in your fork for your changes.
  • Make your changes and tests.
  • Submit a pull request to this repository with your changes.

Roadmap

Here are some of the next planned features for this package:
  • Data persistence using async storage or MMKV, if the user chooses caching persistence. The user will be able to choose that they want persistence and insert the instance within the customized parameters of the config. Example:
inovaflag.config('sdk_key', {
  cacheEnabled: true,
  cacheInstance: mmkvStorage or asyncstorage,
});

This would allow the package to use the desired storage engine to persist resource flag data in cache.

Final considerations

The inova-feature-flag package is an easy way to implement feature flags in your React Native project. By following the installation and configuration steps, you can access feature flags throughout your app using useInovaFlag. Additionally, by using the generic typing feature, you can have strong typing for the feature flag keys and their value types, which can help prevent runtime errors.

Authors

Vinicius Petrachin

Sponsors

Inova e-Business

  • Inova e-Business is a software factory that develops customized systems, apps and e-commerce. For more than 10 years delivering the most innovative technologies and solutions.

License

MIT