Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust types in order to pass props #282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

adjust types in order to pass props #282

wants to merge 1 commit into from

Conversation

dawidvdh
Copy link

@dawidvdh dawidvdh commented Mar 24, 2020

Not sure if this is the best approach, but I have an issue with using the configureFeature like so:

featureOr404.tsx

import {configureFeature} from '@paralleldrive/react-feature-toggles';
import {ComponentType} from 'react';

function featureOr404<T>(
  feature: string,
): (activeComponent: ComponentType<T>) => ComponentType<T> {
  const config = configureFeature<T>(() => null);
  return config(feature);
}

export default featureOr404;

IntroComponent.tsx

import React from 'react';
import {Text} from 'react-native';
import featureOr404 from './featureOr404'

const FEATURE_FLAG = "some-flag";
const Intro = (props: { title: string }) => ( <Text>{title}</Text> );

export default featureOr404(FEATURE_FLAG)(Intro);

IntroScreen.tsx

import React from 'react';
import IntroComponent from './IntroComponent'

const IntroScreen = (props: { title: string }) => ( <IntroComponent title="hello" /> );

export default IntroScreen;

^^^^

problem is that IntroComponent does not know which props it has, so the best solution I had was passing in the Type like so:

in IntroComponent.tsx.

export default featureOr404<Props>(FEATURE_FLAG)(Intro);

Please let me know if there is a better way to achieve this.

@kennylavender
Copy link
Contributor

I don't use TS at all anymore, but this looks fine to me. @jwicks31 can you test this?

@kennylavender kennylavender requested a review from jwicks31 March 27, 2020 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants