posthog-js-lite icon indicating copy to clipboard operation
posthog-js-lite copied to clipboard

feat(flags): FeatureFlag React component

Open haacked opened this issue 8 months ago • 0 comments

I think we can make feature flags easy to use in a declarative fashion with a Feature component.

Is your feature request related to a problem?

It's related to an opportunity to make feature flags easier to use.

Describe the solution you'd like

Here's some example usages:

<Feature featureKey="simple-flag">
  <Section title="Feature Flag">
    The feature flag "simple-flag" is enabled!
  </Section>
</Feature>

<Feature featureKey="simple-flag" variant="variant-1">
  <Section title="Feature Flag">
    The feature flag "simple-flag" is enabled with variant "variant-1"!
  </Section>
</Feature>

<Feature featureKey="simple-flag" variant="variant-2">
  <Section title="Feature Flag">
    The feature flag "simple-flag" is enabled with variant "variant-2"!
  </Section>
</Feature>

<Feature featureKey="simple-flag" negate={true}>
  <Section title="Feature Flag">
    The feature flag "simple-flag" is not enabled!
  </Section>
</Feature>

Describe alternatives you've considered

Alternative is to not do this.

Related sub-libraries

  • [ ] All of them
  • [ ] posthog-web
  • [ ] posthog-node
  • [ ] posthog-ai
  • [x] posthog-react-native

Additional context

Some flags require additional information such as person properties and group properties be passed along. I think a first iteration of this would just ignore that. Or we could add a personProperties property that takes a hash if that's easy to do for React.

haacked avatar Apr 08 '25 02:04 haacked